Skip to content

Commit a486c56

Browse files
committed
update docs and bump version
1 parent bfcac26 commit a486c56

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed

docs/getting_started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ To get started with pointers.py, install the library:
66

77
### Linux/macOS
88

9-
```
9+
```bash
1010
$ python3 -m pip install -U pointers.py
1111
```
1212

1313
### Windows
1414

15-
```
15+
```bash
1616
$ py -3 -m pip install -U pointers.py
1717
```
1818

1919
### From Source
2020

21-
```
21+
```bash
2222
$ git clone https://github.com/ZeroIntensity/pointers.py && cd pointers.py
2323
$ pip install .
2424
```

docs/making_a_program.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Making a Program
2+
3+
Now that we've learned how to use pointers.py, lets build a small script to make `1 == 2`, and then revert our changes (make `1 != 2`).
4+
5+
Lets start out with creating a pointer to `1`, and then moving `2` to it:
6+
7+
```py
8+
from pointers import _
9+
10+
ptr = _&1
11+
ptr <<= 2
12+
13+
assert 1 == 2
14+
```
15+
16+
Running this will work just fine, and no `AssertionError` will be raised.
17+
18+
But how do we revert our changes now? `1` has been overwritten, so we can't just move a `1` back into the pointer.
19+
20+
If you want, you can take a second to think about how to do it.
21+
22+
---
23+
24+
We can cache our `1` by using memory allocation. Since the `1` will be copied to its own memory space, it won't get affected by overwriting `1`.
25+
26+
You can try this out yourself.
27+
28+
```py
29+
from pointers import malloc, _
30+
31+
one = malloc(28)
32+
one <<= 1
33+
34+
ptr = _&1
35+
ptr <<= 2
36+
37+
print(1, ~one)
38+
```
39+
40+
Running this will output `2 1`!
41+
42+
Ok, lets allocate a `1` before we overwrite it:
43+
44+
```py
45+
from pointers import malloc, free, _
46+
47+
cache = malloc(28)
48+
cache <<= 1
49+
50+
ptr = _&1
51+
```
52+
53+
Then, lets move the allocated `1` back into our pointer at the end of the program:
54+
55+
```py
56+
ptr = _&1
57+
ptr <<= 2
58+
59+
assert 1 == 2
60+
61+
ptr <<= ~cache
62+
assert 1 != 2
63+
```
64+
65+
Don't forget to free the memory as well:
66+
67+
```py
68+
free(cache)
69+
```
70+
71+
Here's the final result:
72+
73+
```py
74+
from pointers import malloc, free, _
75+
76+
cache = malloc(28)
77+
cache <<= 1
78+
79+
ptr = _&1
80+
ptr <<= 2
81+
82+
assert 1 == 2
83+
84+
ptr <<= ~cache
85+
assert 1 != 2
86+
free(cache)
87+
```
88+
89+
Go ahead and run this to ensure that everything worked fine.
90+
91+
Congratulations, you have written a working program with pointers.py!

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ nav:
66
- Using Pointers: using_pointers.md
77
- Allocation: allocation.md
88
- C Bindings: bindings.md
9+
- Making a Program: making_a_program.md
910
theme: readthedocs

src/pointers/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.0-rc"
1+
__version__ = "2.0.0"

0 commit comments

Comments
 (0)