mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
9b29358511
Status lines for Emacs and Vim have been added to Python sources so they'll be easier to edit using Python's preferred coding style. Some DNS helper functions have been broken up into multiple files. It's nice to have one function per file whenever possible, since that way we don't need -ffunction-sections. Another reason it's good to have small source files, is because the build will be enforcing resource limits on compilation and testing soon.
53 lines
2.1 KiB
C++
53 lines
2.1 KiB
C++
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│
|
|
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
│ Python 3 │
|
|
│ https://docs.python.org/3/license.html │
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
#include "third_party/python/Include/code.h"
|
|
/* clang-format off */
|
|
|
|
/* This file contains code shared by the compiler and the peephole
|
|
optimizer.
|
|
*/
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
# define PACKOPARG(opcode, oparg) ((_Py_CODEUNIT)(((opcode) << 8) | (oparg)))
|
|
#else
|
|
# define PACKOPARG(opcode, oparg) ((_Py_CODEUNIT)(((oparg) << 8) | (opcode)))
|
|
#endif
|
|
|
|
/* Minimum number of code units necessary to encode instruction with
|
|
EXTENDED_ARGs */
|
|
static int
|
|
instrsize(unsigned int oparg)
|
|
{
|
|
return oparg <= 0xff ? 1 :
|
|
oparg <= 0xffff ? 2 :
|
|
oparg <= 0xffffff ? 3 :
|
|
4;
|
|
}
|
|
|
|
/* 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(_Py_CODEUNIT *codestr, unsigned char opcode,
|
|
unsigned int oparg, int ilen)
|
|
{
|
|
switch (ilen) {
|
|
case 4:
|
|
*codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 24) & 0xff);
|
|
/* fall through */
|
|
case 3:
|
|
*codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 16) & 0xff);
|
|
/* fall through */
|
|
case 2:
|
|
*codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 8) & 0xff);
|
|
/* fall through */
|
|
case 1:
|
|
*codestr++ = PACKOPARG(opcode, oparg & 0xff);
|
|
break;
|
|
default:
|
|
assert(0);
|
|
}
|
|
}
|