aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core-commands.c2
-rw-r--r--src/expressions.c10
-rw-r--r--src/expressions.h16
-rw-r--r--src/lexer.c2
-rw-r--r--src/number-commands.c12
-rw-r--r--src/number-commands.h2
6 files changed, 36 insertions, 8 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index b7e7a60..f7e6f01 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -1453,6 +1453,8 @@ teco_state_control_input(teco_machine_main_t *ctx, gunichar chr, GError **error)
['*'] = {&teco_state_start, teco_state_control_pow},
['/'] = {&teco_state_start, teco_state_control_mod},
['#'] = {&teco_state_start, teco_state_control_xor},
+ ['<'] = {&teco_state_start, teco_state_control_left_shift},
+ ['>'] = {&teco_state_start, teco_state_control_right_shift},
/*
* Commands
diff --git a/src/expressions.c b/src/expressions.c
index e4dc5ad..84d76cb 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -317,6 +317,16 @@ teco_expressions_calc(GError **error)
teco_expressions_push(vleft.i - vright.i);
break;
+ case TECO_OP_SHL:
+ teco_expressions_push((vleft_is_float ? (teco_int_t)vleft.f : vleft.i) <<
+ (vright_is_float ? (teco_int_t)vright.f : vright.i));
+ break;
+
+ case TECO_OP_SHR:
+ teco_expressions_push((vleft_is_float ? (teco_int_t)vleft.f : vleft.i) >>
+ (vright_is_float ? (teco_int_t)vright.f : vright.i));
+ break;
+
case TECO_OP_AND:
teco_expressions_push((vleft_is_float ? (teco_int_t)vleft.f : vleft.i) &
(vright_is_float ? (teco_int_t)vright.f : vright.i));
diff --git a/src/expressions.h b/src/expressions.h
index 1c1b4e9..5d71cd6 100644
--- a/src/expressions.h
+++ b/src/expressions.h
@@ -84,15 +84,17 @@ typedef enum {
/*
* Real operators
*/
- TECO_OP_POW = 0x60, // ^*
- TECO_OP_MOD = 0x50, // ^/
+ TECO_OP_OR = 0x10, // #
+ TECO_OP_XOR = 0x20, // ^#
+ TECO_OP_AND = 0x30, // &
+ TECO_OP_SHL = 0x40, // ^<
+ TECO_OP_SHR, // ^>
+ TECO_OP_SUB = 0x50, // -
+ TECO_OP_ADD, // +
+ TECO_OP_MOD = 0x60, // ^/
TECO_OP_DIV, // /
TECO_OP_MUL, // *
- TECO_OP_SUB = 0x40, // -
- TECO_OP_ADD, // +
- TECO_OP_AND = 0x30, // &
- TECO_OP_XOR = 0x20, // ^#
- TECO_OP_OR = 0x10 // #
+ TECO_OP_POW = 0x70 // ^*
} teco_operator_t;
extern gint teco_num_sign;
diff --git a/src/lexer.c b/src/lexer.c
index 2eae8c4..1eaf6ff 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -46,7 +46,7 @@ teco_lexer_getstyle(teco_view_t *view, teco_machine_main_t *machine,
strchr(",+-*/#&()", chr))
old_style = SCE_SCITECO_OPERATOR;
else if (machine->parent.current == &teco_state_control &&
- strchr("*/#", chr))
+ strchr("<>*/#", chr))
/*
* Two-character operators must always begin with caret
* They get a separate style, so we can extend it back to
diff --git a/src/number-commands.c b/src/number-commands.c
index 6ba2874..0656cf0 100644
--- a/src/number-commands.c
+++ b/src/number-commands.c
@@ -361,6 +361,18 @@ teco_state_start_comma(teco_machine_main_t *ctx, GError **error)
teco_expressions_push_op(TECO_OP_NEW);
}
+void
+teco_state_control_left_shift(teco_machine_main_t *ctx, GError **error)
+{
+ teco_expressions_push_calc(TECO_OP_SHL, error);
+}
+
+void
+teco_state_control_right_shift(teco_machine_main_t *ctx, GError **error)
+{
+ teco_expressions_push_calc(TECO_OP_SHR, error);
+}
+
/*$ ^_ negate
* n^_ -> ~n -- Binary negation
*
diff --git a/src/number-commands.h b/src/number-commands.h
index 79fa77b..98818f7 100644
--- a/src/number-commands.h
+++ b/src/number-commands.h
@@ -35,6 +35,8 @@ void teco_state_start_brace_open(teco_machine_main_t *ctx, GError **error);
void teco_state_start_brace_close(teco_machine_main_t *ctx, GError **error);
void teco_state_start_comma(teco_machine_main_t *ctx, GError **error);
+void teco_state_control_left_shift(teco_machine_main_t *ctx, GError **error);
+void teco_state_control_right_shift(teco_machine_main_t *ctx, GError **error);
void teco_state_control_negate(teco_machine_main_t *ctx, GError **error);
void teco_state_control_pow(teco_machine_main_t *ctx, GError **error);
void teco_state_control_mod(teco_machine_main_t *ctx, GError **error);