aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ls_expr.c27
-rw-r--r--lib/ls_lex.c4
-rw-r--r--lib/ls_types.h2
3 files changed, 32 insertions, 1 deletions
diff --git a/lib/ls_expr.c b/lib/ls_expr.c
index f2e4bfc..3c5581b 100644
--- a/lib/ls_expr.c
+++ b/lib/ls_expr.c
@@ -90,6 +90,8 @@ static ls_int_t _sub_int_int(ls_int_t lhs, ls_int_t rhs);
static ls_int_t _mul_int_int(ls_int_t lhs, ls_int_t rhs);
static ls_int_t _div_int_int(ls_int_t lhs, ls_int_t rhs);
static ls_int_t _mod_int_int(ls_int_t lhs, ls_int_t rhs);
+static ls_int_t _shl_int_int(ls_int_t lhs, ls_int_t rhs);
+static ls_int_t _shr_int_int(ls_int_t lhs, ls_int_t rhs);
static ls_int_t _abs_int(ls_int_t lhs, ls_int_t rhs);
static ls_int_t _neg_int(ls_int_t lhs, ls_int_t rhs);
@@ -124,6 +126,9 @@ static const ls_opdef_t _ops[] = {
[LS_OP_ADD] = { 11, false, false, &_add_int_int },
[LS_OP_SUB] = { 11, false, false, &_sub_int_int },
+ [LS_OP_SHL] = { 10, false, false, &_shl_int_int },
+ [LS_OP_SHR] = { 10, false, false, &_shr_int_int },
+
[LS_OP_LT] = { 9, false, false, &_lt_int_int },
[LS_OP_GT] = { 9, false, false, &_gt_int_int },
[LS_OP_LEQ] = { 9, false, false, &_leq_int_int },
@@ -425,6 +430,28 @@ _mod_int_int(ls_int_t lhs, ls_int_t rhs)
}
static ls_int_t
+_shl_int_int(ls_int_t lhs, ls_int_t rhs)
+{
+ if (rhs < 0)
+ return _shr_int_int(lhs, -rhs);
+ else if (rhs > 32)
+ return 0;
+ else
+ return lhs << rhs;
+}
+
+static ls_int_t
+_shr_int_int(ls_int_t lhs, ls_int_t rhs)
+{
+ if (rhs < 0)
+ return _shl_int_int(lhs, -rhs);
+ else if (rhs > 32)
+ return 0;
+ else
+ return lhs >> rhs;
+}
+
+static ls_int_t
_abs_int(ls_int_t lhs, ls_int_t rhs)
{
(void) lhs;
diff --git a/lib/ls_lex.c b/lib/ls_lex.c
index a5908dd..4de0318 100644
--- a/lib/ls_lex.c
+++ b/lib/ls_lex.c
@@ -64,7 +64,7 @@ typedef enum {
static const uint8_t _ch_kind_lut[32] = {
K(CH_KIND_SPACE, CH_KIND_OPER), // space !
K(CH_KIND_STR, CH_KIND_SIGIL), // " #
- K(CH_KIND_SIGIL, CH_KIND_SIGIL), // $ %
+ K(CH_KIND_SIGIL, CH_KIND_OPER), // $ %
K(CH_KIND_DIGIT, CH_KIND_REM), // & '
K(CH_KIND_OPER, CH_KIND_OPER), // ( )
K(CH_KIND_OPER, CH_KIND_OPER), // * +
@@ -102,6 +102,8 @@ static const ls_uchar _ops[][2] = {
[LS_OP_LEQ] = "<=",
[LS_OP_GEQ] = ">=",
[LS_OP_NEQ] = "<>",
+ [LS_OP_SHL] = "<<",
+ [LS_OP_SHR] = ">>",
[LS_OP_LPAREN] = "(",
[LS_OP_RPAREN] = ")",
[LS_OP_MOD] = "%",
diff --git a/lib/ls_types.h b/lib/ls_types.h
index 7b8d218..15ef207 100644
--- a/lib/ls_types.h
+++ b/lib/ls_types.h
@@ -300,6 +300,8 @@ typedef enum {
LS_OP_LEQ,
LS_OP_GEQ,
LS_OP_NEQ,
+ LS_OP_SHL,
+ LS_OP_SHR,
// Single char
LS_OP_LPAREN,