/
interpreter.tbl
122 lines (111 loc) · 6.92 KB
/
interpreter.tbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// *****************************************************************************
// interpreter.tbl XL project
// *****************************************************************************
//
// File description:
//
// Opcode interpretation
//
// Normally, opcodes defined here should match those in llvm.tbl
// although there is strictly speaking no reason other than
// the convenience for maintaining builtins.xl
//
//
//
//
// *****************************************************************************
// This software is licensed under the GNU General Public License v3+
// (C) 2015-2019, Christophe de Dinechin <christophe@dinechin.org>
// *****************************************************************************
// This file is part of XL
//
// XL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// XL is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with XL, in a file named COPYING.
// If not, see <https://www.gnu.org/licenses/>.
// *****************************************************************************
BINARY_OP(Add, Natural, Natural, Natural, R_INT ( LEFT + RIGHT))
BINARY_OP(FAdd, Real, Real, Real, R_REAL( LEFT + RIGHT))
BINARY_OP(Sub, Natural, Natural, Natural, R_INT ( LEFT - RIGHT))
BINARY_OP(FSub, Real, Real, Real, R_REAL( LEFT - RIGHT))
BINARY_OP(Mul, Natural, Natural, Natural, R_INT ( LEFT * RIGHT))
BINARY_OP(FMul, Real, Real, Real, R_REAL( LEFT * RIGHT))
BINARY_OP(UDiv, Natural, Natural, Natural, R_INT (ULEFT / URIGHT0))
BINARY_OP(SDiv, Natural, Natural, Natural, R_INT ( LEFT / RIGHT0))
BINARY_OP(FDiv, Real, Real, Real, R_REAL( LEFT / RIGHT0))
BINARY_OP(URem, Natural, Natural, Natural, R_INT (ULEFT % URIGHT0))
BINARY_OP(SRem, Natural, Natural, Natural, R_INT ( LEFT % RIGHT0))
BINARY_OP(FRem, Real, Real, Real, R_INT (fmod(LEFT,RIGHT0)))
BINARY_OP(Shl, Natural, Natural, Natural, R_INT ( LEFT << RIGHT))
BINARY_OP(LShr, Natural, Natural, Natural, R_INT (ULEFT >> RIGHT))
BINARY_OP(AShr, Natural, Natural, Natural, R_INT ( LEFT >> RIGHT))
BINARY_OP(And, Natural, Natural, Natural, R_INT ( LEFT & RIGHT))
BINARY_OP(Or, Natural, Natural, Natural, R_INT ( LEFT | RIGHT))
BINARY_OP(Xor, Natural, Natural, Natural, R_INT ( LEFT ^ RIGHT))
UNARY_OP(Neg, Natural, Natural, R_INT (-SLEFT))
UNARY_OP(FNeg, Real, Real, R_REAL(-LEFT))
UNARY_OP(Not, Natural, Natural, R_INT (~LEFT))
BINARY_OP(ICmpEQ, Name, Natural, Natural, R_BOOL( LEFT == RIGHT))
BINARY_OP(ICmpNE, Name, Natural, Natural, R_BOOL( LEFT != RIGHT))
BINARY_OP(ICmpUGT, Name, Natural, Natural, R_BOOL(ULEFT > URIGHT))
BINARY_OP(ICmpUGE, Name, Natural, Natural, R_BOOL(ULEFT >= URIGHT))
BINARY_OP(ICmpULT, Name, Natural, Natural, R_BOOL(ULEFT < URIGHT))
BINARY_OP(ICmpULE, Name, Natural, Natural, R_BOOL(ULEFT <= URIGHT))
BINARY_OP(ICmpSGT, Name, Natural, Natural, R_BOOL(SLEFT > SRIGHT))
BINARY_OP(ICmpSGE, Name, Natural, Natural, R_BOOL(SLEFT >= SRIGHT))
BINARY_OP(ICmpSLT, Name, Natural, Natural, R_BOOL(SLEFT < SRIGHT))
BINARY_OP(ICmpSLE, Name, Natural, Natural, R_BOOL(SLEFT <= SRIGHT))
// The following relies on 'true' > 'false' alphabetically!!!
BINARY_OP(BCmpEQ, Name, Name, Name, R_BOOL( LEFT == RIGHT))
BINARY_OP(BCmpNE, Name, Name, Name, R_BOOL( LEFT != RIGHT))
BINARY_OP(BCmpGT, Name, Name, Name, R_BOOL( LEFT > RIGHT))
BINARY_OP(BCmpGE, Name, Name, Name, R_BOOL( LEFT >= RIGHT))
BINARY_OP(BCmpLT, Name, Name, Name, R_BOOL( LEFT < RIGHT))
BINARY_OP(BCmpLE, Name, Name, Name, R_BOOL( LEFT <= RIGHT))
BINARY_OP(FCmpOEQ, Name, Real, Real, R_BOOL(LEFT == RIGHT))
BINARY_OP(FCmpONE, Name, Real, Real, R_BOOL(LEFT != RIGHT))
BINARY_OP(FCmpOGT, Name, Real, Real, R_BOOL(LEFT > RIGHT))
BINARY_OP(FCmpOGE, Name, Real, Real, R_BOOL(LEFT >= RIGHT))
BINARY_OP(FCmpOLT, Name, Real, Real, R_BOOL(LEFT < RIGHT))
BINARY_OP(FCmpOLE, Name, Real, Real, R_BOOL(LEFT <= RIGHT))
// BINARY_OP(FCmpORD, Name, Real, Real, R_BOOL(LEFT == RIGHT))
// BINARY_OP(FCmpUNO, Name, Real, Real, R_BOOL(LEFT == RIGHT))
BINARY_OP(FCmpUEQ, Name, Real, Real, R_BOOL(LEFT == RIGHT))
BINARY_OP(FCmpUNE, Name, Real, Real, R_BOOL(LEFT != RIGHT))
BINARY_OP(FCmpUGT, Name, Real, Real, R_BOOL(LEFT > RIGHT))
BINARY_OP(FCmpUGE, Name, Real, Real, R_BOOL(LEFT >= RIGHT))
BINARY_OP(FCmpULT, Name, Real, Real, R_BOOL(LEFT < RIGHT))
BINARY_OP(FCmpULE, Name, Real, Real, R_BOOL(LEFT <= RIGHT))
BINARY_OP(BCmpUEQ, Name, Name, Name, R_BOOL(LEFT_B == RIGHT_B))
BINARY_OP(BCmpUNE, Name, Name, Name, R_BOOL(LEFT_B != RIGHT_B))
BINARY_OP(BCmpUGT, Name, Name, Name, R_BOOL(LEFT_B > RIGHT_B))
BINARY_OP(BCmpUGE, Name, Name, Name, R_BOOL(LEFT_B >= RIGHT_B))
BINARY_OP(BCmpULT, Name, Name, Name, R_BOOL(LEFT_B < RIGHT_B))
BINARY_OP(BCmpULE, Name, Name, Name, R_BOOL(LEFT_B <= RIGHT_B))
BINARY_OP(BAnd, Name, Name, Name, R_BOOL(LEFT_B and RIGHT_B))
BINARY_OP(BOr, Name, Name, Name, R_BOOL(LEFT_B or RIGHT_B))
BINARY_OP(BXor, Name, Name, Name, R_BOOL(LEFT_B xor RIGHT_B))
UNARY_OP(BNot, Name, Name, R_BOOL(not LEFT_B))
// ============================================================================
//
// Special opcodes that perform XL-specific operations
//
// ============================================================================
UNARY_OP(TreeKind, Natural, Tree, R_INT (left.Kind()))
UNARY_OP(TreeLeft, Tree, Prefix, RESULT(left.left))
UNARY_OP(TreeRight, Tree, Prefix, RESULT(left.right))
UNARY_OP(InfixName, Text, Infix, R_TEXT(left.name))
UNARY_OP(TextOpening, Text, Text, R_TEXT(left.opening))
UNARY_OP(TextClosing, Text, Text, R_TEXT(left.closing))
UNARY_OP(BlockChild, Tree, Block, RESULT(left.child))
UNARY_OP(BlockOpening, Text, Block, R_TEXT(left.opening))
UNARY_OP(BlockClosing, Text, Block, R_TEXT(left.closing))