Skip to content

Commit b5f10c2

Browse files
committed
[truffle] Add nqp::const
1 parent b8b625c commit b5f10c2

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

src/vm/jvm/Truffle.nqp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,119 @@ my %type_names;
1515
%type_names{$CALL_ARG} := 'CALL_ARG';
1616
%type_names{$RETVAL} := 'RETVAL';
1717

18+
# Constant mapping.
19+
my %const_map;
20+
%const_map{'CCLASS_ANY'} := 65535;
21+
%const_map{'CCLASS_UPPERCASE'} := 1;
22+
%const_map{'CCLASS_LOWERCASE'} := 2;
23+
%const_map{'CCLASS_ALPHABETIC'} := 4;
24+
%const_map{'CCLASS_NUMERIC'} := 8;
25+
%const_map{'CCLASS_HEXADECIMAL'} := 16;
26+
%const_map{'CCLASS_WHITESPACE'} := 32;
27+
%const_map{'CCLASS_PRINTING'} := 64;
28+
%const_map{'CCLASS_BLANK'} := 256;
29+
%const_map{'CCLASS_CONTROL'} := 512;
30+
%const_map{'CCLASS_PUNCTUATION'} := 1024;
31+
%const_map{'CCLASS_ALPHANUMERIC'} := 2048;
32+
%const_map{'CCLASS_NEWLINE'} := 4096;
33+
%const_map{'CCLASS_WORD'} := 8192;
34+
35+
%const_map{'HLL_ROLE_NONE'} := 0;
36+
%const_map{'HLL_ROLE_INT'} := 1;
37+
%const_map{'HLL_ROLE_NUM'} := 2;
38+
%const_map{'HLL_ROLE_STR'} := 3;
39+
%const_map{'HLL_ROLE_ARRAY'} := 4;
40+
%const_map{'HLL_ROLE_HASH'} := 5;
41+
%const_map{'HLL_ROLE_CODE'} := 6;
42+
%const_map{'CONTROL_NEXT'} := 4;
43+
%const_map{'CONTROL_REDO'} := 8;
44+
%const_map{'CONTROL_LAST'} := 16;
45+
%const_map{'CONTROL_RETURN'} := 32;
46+
%const_map{'CONTROL_TAKE'} := 128;
47+
%const_map{'CONTROL_WARN'} := 256;
48+
%const_map{'CONTROL_SUCCEED'} := 512;
49+
%const_map{'CONTROL_PROCEED'} := 1024;
50+
%const_map{'CONTROL_LABELED'} := 4096;
51+
%const_map{'CONTROL_AWAIT'} := 8192;
52+
%const_map{'CONTROL_EMIT'} := 16384;
53+
%const_map{'CONTROL_DONE'} := 32768;
54+
55+
%const_map{'STAT_EXISTS'} := 0;
56+
%const_map{'STAT_FILESIZE'} := 1;
57+
%const_map{'STAT_ISDIR'} := 2;
58+
%const_map{'STAT_ISREG'} := 3;
59+
%const_map{'STAT_ISDEV'} := 4;
60+
%const_map{'STAT_CREATETIME'} := 5;
61+
%const_map{'STAT_ACCESSTIME'} := 6;
62+
%const_map{'STAT_MODIFYTIME'} := 7;
63+
%const_map{'STAT_CHANGETIME'} := 8;
64+
%const_map{'STAT_BACKUPTIME'} := 9;
65+
%const_map{'STAT_UID'} := 10;
66+
%const_map{'STAT_GID'} := 11;
67+
%const_map{'STAT_ISLNK'} := 12;
68+
%const_map{'STAT_PLATFORM_DEV'} := -1;
69+
%const_map{'STAT_PLATFORM_INODE'} := -2;
70+
%const_map{'STAT_PLATFORM_MODE'} := -3;
71+
%const_map{'STAT_PLATFORM_NLINKS'} := -4;
72+
%const_map{'STAT_PLATFORM_DEVTYPE'} := -5;
73+
%const_map{'STAT_PLATFORM_BLOCKSIZE'} := -6;
74+
%const_map{'STAT_PLATFORM_BLOCKS'} := -7;
75+
76+
%const_map{'PIPE_INHERIT_IN'} := 1;
77+
%const_map{'PIPE_IGNORE_IN'} := 2;
78+
%const_map{'PIPE_CAPTURE_IN'} := 4;
79+
%const_map{'PIPE_INHERIT_OUT'} := 8,
80+
%const_map{'PIPE_IGNORE_OUT'} := 16;
81+
%const_map{'PIPE_CAPTURE_OUT'} := 32;
82+
%const_map{'PIPE_INHERIT_ERR'} := 64;
83+
%const_map{'PIPE_IGNORE_ERR'} := 128;
84+
%const_map{'PIPE_CAPTURE_ERR'} := 256;
85+
%const_map{'PIPE_MERGED_OUT_ERR'} := 512;
86+
87+
# could probably support a few more...
88+
%const_map{'SIG_INT'} := 2;
89+
%const_map{'SIG_KILL'} := 9;
90+
91+
%const_map{'TYPE_CHECK_CACHE_DEFINITIVE'} := 0;
92+
%const_map{'TYPE_CHECK_CACHE_THEN_METHOD'} := 1;
93+
%const_map{'TYPE_CHECK_NEEDS_ACCEPTS'} := 2;
94+
95+
%const_map{'C_TYPE_CHAR'} := -1;
96+
%const_map{'C_TYPE_SHORT'} := -2;
97+
%const_map{'C_TYPE_INT'} := -3;
98+
%const_map{'C_TYPE_LONG'} := -4;
99+
%const_map{'C_TYPE_LONGLONG'} := -5;
100+
%const_map{'C_TYPE_SIZE_T'} := -6;
101+
%const_map{'C_TYPE_BOOL'} := -7;
102+
%const_map{'C_TYPE_ATOMIC_INT'} := -8;
103+
%const_map{'C_TYPE_FLOAT'} := -1;
104+
%const_map{'C_TYPE_DOUBLE'} := -2;
105+
%const_map{'C_TYPE_LONGDOUBLE'} := -3;
106+
107+
%const_map{'NORMALIZE_NONE'} := 0;
108+
%const_map{'NORMALIZE_NFC'} := 1;
109+
%const_map{'NORMALIZE_NFD'} := 2;
110+
%const_map{'NORMALIZE_NFKC'} := 3;
111+
%const_map{'NORMALIZE_NFKD'} := 4;
112+
113+
%const_map{'RUSAGE_UTIME_SEC'} := 0;
114+
%const_map{'RUSAGE_UTIME_MSEC'} := 1;
115+
%const_map{'RUSAGE_STIME_SEC'} := 2;
116+
%const_map{'RUSAGE_STIME_MSEC'} := 3;
117+
%const_map{'RUSAGE_MAXRSS'} := 4;
118+
%const_map{'RUSAGE_IXRSS'} := 5;
119+
%const_map{'RUSAGE_IDRSS'} := 6;
120+
%const_map{'RUSAGE_ISRSS'} := 7;
121+
%const_map{'RUSAGE_MINFLT'} := 8;
122+
%const_map{'RUSAGE_MAJFLT'} := 9;
123+
%const_map{'RUSAGE_NSWAP'} := 10;
124+
%const_map{'RUSAGE_INBLOCK'} := 11;
125+
%const_map{'RUSAGE_OUBLOCK'} := 12;
126+
%const_map{'RUSAGE_MSGSND'} := 13;
127+
%const_map{'RUSAGE_MSGRCV'} := 14;
128+
%const_map{'RUSAGE_NSIGNALS'} := 15;
129+
%const_map{'RUSAGE_NVCSW'} := 16;
130+
%const_map{'RUSAGE_NIVCSW'} := 17;
18131

19132
class TAST {
20133
has int $!type;
@@ -113,6 +226,14 @@ class QAST::OperationsTruffle {
113226
}, :$inlinable, :$hll);
114227
}
115228

229+
add_op('const', sub ($comp, $node, :$want) {
230+
if nqp::existskey(%const_map, $node.name) {
231+
$comp.as_truffle(QAST::IVal.new( :value(%const_map{$node.name}) ), :$want)
232+
}
233+
else {
234+
nqp::die("Unknown constant '" ~ $node.name ~ "'");
235+
}
236+
});
116237

117238
for <while until repeat_while repeat_until> -> $op {
118239
add_op($op, sub ($comp, $node, :$want) {

0 commit comments

Comments
 (0)