mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-29 08:42:28 +00:00
Experiment with making Python go faster
The goal is to put the compiled pyc files in the APE ZIP.
This commit is contained in:
parent
4486ad5c9e
commit
ebb8c85496
33 changed files with 9483 additions and 1859 deletions
|
@ -4,22 +4,40 @@
|
|||
│ Python 3 │
|
||||
│ https://docs.python.org/3/license.html │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "third_party/python/Include/bytesobject.h"
|
||||
#include "third_party/python/Include/compile.h"
|
||||
#include "third_party/python/Include/fileutils.h"
|
||||
#include "third_party/python/Include/import.h"
|
||||
#include "third_party/python/Include/marshal.h"
|
||||
#include "third_party/python/Include/pydebug.h"
|
||||
#include "third_party/python/Include/pylifecycle.h"
|
||||
#include "third_party/python/Include/pymacro.h"
|
||||
#include "third_party/python/Include/pythonrun.h"
|
||||
/* clang-format off */
|
||||
|
||||
#define HEADER "\
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│\n\
|
||||
│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│\n\
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡\n\
|
||||
│ Python 3 │\n\
|
||||
│ https://docs.python.org/3/license.html │\n\
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/\n\
|
||||
/* clang-format off */\n\
|
||||
\n\
|
||||
/*\n\
|
||||
* Auto-generated by\n\
|
||||
* %s \\\n\
|
||||
* %s \\\n\
|
||||
* %s\n\
|
||||
*/\n\
|
||||
\n\
|
||||
"
|
||||
|
||||
/* This is built as a stand-alone executable by the Makefile, and helps turn
|
||||
Lib/importlib/_bootstrap.py into a frozen module in Python/importlib.h
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
#include <marshal.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef MS_WINDOWS
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* To avoid a circular dependency on frozen.o, we create our own structure
|
||||
of frozen modules instead, left deliberately blank so as to avoid
|
||||
unintentional import of a stale version of _frozen_importlib. */
|
||||
|
@ -35,7 +53,25 @@ static const struct _frozen _PyImport_FrozenModules[] = {
|
|||
const struct _frozen *PyImport_FrozenModules;
|
||||
#endif
|
||||
|
||||
const char header[] = "/* Auto-generated by Programs/_freeze_importlib.c */";
|
||||
PyObject *PyMarshal_Init(void);
|
||||
PyObject *PyInit_gc(void);
|
||||
PyObject *PyInit__ast(void);
|
||||
PyObject *_PyWarnings_Init(void);
|
||||
PyObject *PyInit__string(void);
|
||||
|
||||
struct _inittab _PyImport_Inittab[] = {
|
||||
{"marshal", PyMarshal_Init},
|
||||
{"_imp", PyInit_imp},
|
||||
{"_ast", PyInit__ast},
|
||||
{"builtins"},
|
||||
{"sys"},
|
||||
{"gc", PyInit_gc},
|
||||
{"_warnings", _PyWarnings_Init},
|
||||
{"_string", PyInit__string},
|
||||
{0}
|
||||
};
|
||||
|
||||
struct _inittab *PyImport_Inittab = _PyImport_Inittab;
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
|
@ -120,7 +156,7 @@ main(int argc, char *argv[])
|
|||
fprintf(stderr, "cannot open '%s' for writing\n", outpath);
|
||||
goto error;
|
||||
}
|
||||
fprintf(outfile, "%s\n", header);
|
||||
fprintf(outfile, HEADER, argv[0], argv[1], argv[2]);
|
||||
if (is_bootstrap)
|
||||
fprintf(outfile, "const unsigned char _Py_M__importlib[] = {\n");
|
||||
else
|
3
third_party/python/Programs/python.c
vendored
3
third_party/python/Programs/python.c
vendored
|
@ -27,6 +27,9 @@
|
|||
#include "third_party/python/Include/unicodeobject.h"
|
||||
/* clang-format off */
|
||||
|
||||
extern struct _inittab _PyImport_Inittab[];
|
||||
struct _inittab *PyImport_Inittab = _PyImport_Inittab;
|
||||
|
||||
static jmp_buf jbuf;
|
||||
|
||||
static void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue