From 2b74fc847ee12c2722549305f10bef6cbde44df1 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 14 Apr 2024 01:51:14 +0800 Subject: [PATCH] Update precompile.md --- docs/features/precompile.md | 11 ++++++++--- tests/94_compile.py | 14 -------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/docs/features/precompile.md b/docs/features/precompile.md index f0c60f0e..5b4b23a2 100644 --- a/docs/features/precompile.md +++ b/docs/features/precompile.md @@ -3,7 +3,7 @@ icon: dot title: Precompiling --- -pkpy allows you to precompile your python code into a special form, which can be executed later. +pkpy allows you to precompile python code into two special forms, which can be executed later. ### In-memory precompilation @@ -15,8 +15,9 @@ CodeObject_ code = vm->compile("print('Hello, world!')", "", EXEC_MODE); vm->_exec(code); // Hello, world! ``` -This `CodeObject_` object is a very non-generic form of the compiled code. -It is an in-memory form. You are not able to save it to a file or load it from a file. +This `CodeObject_` object is a very non-generic form of the compiled code, +which is an in-memory form. Very efficient, but not portable. +You are not able to save it to a file or load it from a file. ### String precompilation @@ -112,3 +113,7 @@ Traceback (most recent call last): return g(a, b) StackOverflowError ``` + +!!! +String compilation has no guarantee of compatibility between different versions of pkpy. +!!! diff --git a/tests/94_compile.py b/tests/94_compile.py index bb9ae4e0..fd90e88a 100644 --- a/tests/94_compile.py +++ b/tests/94_compile.py @@ -1,16 +1,2 @@ code = compile("1+2", "", "eval") assert eval(code) == 3 - -src = """ -def f(a, b): - return g(a, b) - -def g(a, b): - c = f(a, b) - d = g(a, b) - return c + d -""" - -code = compile(src, "<12>", "exec") -exec(code) -f(1, 2)