Skip to content

Commit a223c72

Browse files
committed
[docs/caffeine] General improvements
1 parent 8d63382 commit a223c72

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

docs/caffeine.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,53 @@
88
- [Python API](python-api.md)
99
- **Caffeine ▾**
1010
- [Introduction](#introduction)
11+
- [Basic Usage](#basic-usage)
12+
- [Notice](#notice)
1113
- [Standard Library](stdlib.md)
1214

1315
## Introduction
1416

15-
This document is coming soon.
17+
Caffeine is a x++ to Python conversion module and CLI. It converts your existing code to Python for performance improvements or just general codebase migration.
18+
It's included with x++ since version 3.1.2 and is available globally as the Python package `caffeine`.
19+
20+
It implements **all** features available in xpp except for imports.
21+
22+
## Basic Usage
23+
24+
If you had a file called `main.xpp` and wanted to convert it to Python, you could do something like this:
25+
26+
```sh
27+
caffeine main.xpp
28+
```
29+
30+
This will give you a `main.py` file in the same directory.
31+
32+
---
33+
34+
Another feature is auto minification of the resulting Python code via the `-1` flag.
35+
To convert `main.xpp` to minified Python, you would run:
36+
37+
```sh
38+
caffeine -o -1 main.xpp
39+
```
40+
41+
Notice the `-o` in there? That stands for `overwrite`, so caffeine will write over the existing `main.py` file (if it exists).
42+
43+
---
44+
45+
Lastly, Caffeine supports automatic building via [pyinstaller](https://pyinstaller.org).
46+
To convert `main.xpp` to an exe (or binary, depending on your OS) and then run it automatically, you can do something like this:
47+
48+
```sh
49+
caffeine -o -r -b main.xpp
50+
```
51+
52+
This will give you a `main` file and will run it automatically after pyinstaller builds it.
53+
However, this obviouslly requires that you have pyinstaller installed and added to system PATH.
54+
55+
## Notice
56+
57+
Run `caffeine --help` for more up to date and accurate information then these docs can provide.
1658

1759
---
1860

docs/documents/datatypes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ prt myInteger :: 5
134134
In vanilla x++, it can also be used as a boolean value, where `1` represents `true` and `0` represents `false`:
135135

136136
```xpp
137-
psh hamburgerIsEaten 1
138-
if (hamburgerIsEaten == 1) "prt 'Someone ate my hamburger'"
137+
var hamburgerIsEaten 1
138+
if (hamburgerIsEaten == 1) { prt "Someone ate my hamburger" }
139139
```
140140

141141
---
@@ -154,7 +154,7 @@ It cannot be modified using any operators, and it cannot be used as a source or
154154

155155
```xpp
156156
:: This will throw a parsing exception
157-
if (nonexistingVariable == anotherNonExistingVariable) "prt 'true'"
157+
if (nonexistingVariable == anotherNonExistingVariable) { prt "true" }
158158
```
159159

160160
---
@@ -218,15 +218,15 @@ prt ("Hello, " + secondString) :: "Hello, world!"
218218
219219
:: If you have other datatypes:
220220
var myInteger 5
221-
prt "My favorite integer: " (myInteger)
221+
prt "My favorite integer:" (myInteger)
222222
```
223223

224224
Any non-string data type within a string interpolation will require the use of `()`.
225225

226226
When being compared against using mathematical comparators, it is compared lexicographically:
227227

228228
```xpp
229-
if "abc" < "cba" "prt 'true'"
229+
if ("abc" < "cba") { prt "true" }
230230
```
231231

232232
---

src/caffeine/__main__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
except ImportError:
1919
minify = None
2020

21-
# Locate GCC
22-
GCC_PATH = which("gcc")
23-
2421
# Initialization
2522
def do_run(file: str) -> None:
2623
file = str(file)

src/caffeine/modules/operators/math.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ def operator_pow(func: object, args: list) -> None:
4343
@operator("rnd")
4444
def operator_rnd(func: object, args: list) -> None:
4545
if len(args) == 3:
46-
return func.append(f"{args[2]} = round({convert_value(args[0])}, {convert_value(args[1])})")
46+
return func.append(f"{args[2].lstrip('?')} = round({convert_value(args[0])}, {convert_value(args[1])})")
4747

48-
func.append(f"{args[1]} = round({convert_value(args[0])})")
48+
func.append(f"{args[1].lstrip('?')} = round({convert_value(args[0])})")
4949

5050
@operator("rng")
5151
def operator_rng(func: object, args: list) -> None:
52-
func.append(f"{args[2]} = random.randint({convert_value(args[0])}, {convert_value(args[1])})")
52+
func.prepend("import random")
53+
func.append(f"{args[2].lstrip('?')} = random.randint({convert_value(args[0])}, {convert_value(args[1])})")
5354

5455
@operator("sub")
5556
def operator_sub(func: object, args: list) -> None:

0 commit comments

Comments
 (0)