mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
Update precompile.md
This commit is contained in:
parent
57574bd8be
commit
2b74fc847e
@ -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!')", "<string>", 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.
|
||||
!!!
|
||||
|
@ -1,16 +1,2 @@
|
||||
code = compile("1+2", "<eval>", "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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user