From b0f80b0312a99ca46323efc0e4d09b567553ed46 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 24 May 2016 09:15:14 +0300 Subject: Issue #26647: Python interpreter now uses 16-bit wordcode instead of bytecode. Patch by Demur Rumed. --- Python/wordcode_helpers.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Python/wordcode_helpers.h (limited to 'Python/wordcode_helpers.h') diff --git a/Python/wordcode_helpers.h b/Python/wordcode_helpers.h new file mode 100644 index 0000000000..b61ba33d8f --- /dev/null +++ b/Python/wordcode_helpers.h @@ -0,0 +1,38 @@ +/* This file contains code shared by the compiler and the peephole + optimizer. + */ + +/* Minimum number of bytes necessary to encode instruction with EXTENDED_ARGs */ +static int +instrsize(unsigned int oparg) +{ + return oparg <= 0xff ? 2 : + oparg <= 0xffff ? 4 : + oparg <= 0xffffff ? 6 : + 8; +} + +/* Spits out op/oparg pair using ilen bytes. codestr should be pointed at the + desired location of the first EXTENDED_ARG */ +static void +write_op_arg(unsigned char *codestr, unsigned char opcode, + unsigned int oparg, int ilen) +{ + switch (ilen) { + case 8: + *codestr++ = EXTENDED_ARG; + *codestr++ = (oparg >> 24) & 0xff; + case 6: + *codestr++ = EXTENDED_ARG; + *codestr++ = (oparg >> 16) & 0xff; + case 4: + *codestr++ = EXTENDED_ARG; + *codestr++ = (oparg >> 8) & 0xff; + case 2: + *codestr++ = opcode; + *codestr++ = oparg & 0xff; + break; + default: + assert(0); + } +} -- cgit v1.2.1