flavour-pvm 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,176 @@
1
+ Metadata-Version: 2.4
2
+ Name: flavour-pvm
3
+ Version: 1.0.0
4
+ Summary: A custom vernacular Python dialect powered by a stack-based Mini-PVM
5
+ Author-email: Rahul Deb <your-email@example.com>
6
+ License-Expression: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+
12
+ # 🌢️ Flavour: Custom-Keyword Python Dialect & Virtual Machine (Mini-PVM)
13
+
14
+ > **A custom vernacular Python dialect featuring an authentic Stack-Based Virtual Machine (Mini-PVM), Bytecode Compiler with Jump Backpatching, Disassembler, and Source Transpiler.**
15
+
16
+ Flavour allows developers to write code using custom vernacular keywordsβ€”such as **Hinglish** (`agar`, `warna`, `jabtak`, `likho`, `har`, `mein`) or **Gen-Z** (`lowkey`, `deadass`, `spin`, `spill`).
17
+
18
+ Unlike simple text-replacement tools, Flavour provides a **genuine Stack-Based Bytecode Virtual Machine (Mini-PVM)** that compiles source code into low-level bytecode instructions and executes them on an evaluation stackβ€”mirroring how CPython's `ceval.c` works.
19
+
20
+ ---
21
+
22
+ ## πŸ›οΈ System Architecture
23
+
24
+ ```mermaid
25
+ flowchart TD
26
+ A[".mypy Source Code (Hinglish / Gen-Z)"] --> B["Lexer (Tokenizer)"]
27
+ B --> C["Recursive Descent Parser (AST)"]
28
+ C --> D["Bytecode Compiler (Jump Backpatching)"]
29
+ D --> E["Bytecode Instructions (Opcodes + Args)"]
30
+
31
+ subgraph PVM ["Mini-PVM (Stack-Based Virtual Machine)"]
32
+ F["Instruction Pointer (IP)"]
33
+ G["Operand Stack"]
34
+ H["Frame Environment (Symbol Table)"]
35
+ E --> F
36
+ F --> I["Fetch -> Decode -> Execute Loop"]
37
+ I <--> G
38
+ I <--> H
39
+ I --> J["Console Output"]
40
+ end
41
+
42
+ E --> K["Bytecode Disassembler ('dis')"]
43
+ A -.-> L["Transpiler Mode (Optional exec)"]
44
+ ```
45
+
46
+ ---
47
+
48
+ ## ⚑ Quick Start
49
+
50
+ Zero external dependenciesβ€”uses 100% standard Python 3!
51
+
52
+ ### 1. Execute Directly on the Mini-PVM
53
+ ```bash
54
+ python flavour.py examples/loop.mypy
55
+ ```
56
+ ```bash
57
+ python flavour.py examples/fizzbuzz.mypy
58
+ ```
59
+
60
+ ### 2. Disassemble and View Bytecode (The PVM Inspector)
61
+ Shows the compiled instruction stream, opcodes, and jump target addresses:
62
+ ```bash
63
+ python flavour.py dis examples/loop.mypy
64
+ ```
65
+ ```text
66
+ ADDR OPCODE ARGUMENT / TARGET
67
+ -------------------------------------------------------
68
+ 0000 LOAD_CONST '=== Mini-PVM While Loop Demo ==='
69
+ 0001 PRINT_VALUE
70
+ 0002 LOAD_CONST 1
71
+ 0003 STORE_NAME 'ginti'
72
+ 0004 LOAD_CONST 0
73
+ 0005 STORE_NAME 'kul_jod'
74
+ 0006 LOAD_NAME 'ginti'
75
+ 0007 LOAD_CONST 5
76
+ 0008 COMPARE_OP '<='
77
+ 0009 POP_JUMP_IF_FALSE to 0029
78
+ ...
79
+ 0028 JUMP_ABSOLUTE to 0006
80
+ 0029 LOAD_CONST '--- Loop Completed ---'
81
+ 0030 PRINT_VALUE
82
+ 0036 HALT
83
+ ```
84
+
85
+ ### 3. Launch the Interactive REPL on Mini-PVM
86
+ ```bash
87
+ python flavour.py repl
88
+ ```
89
+ ```python
90
+ >>> x = 10
91
+ >>> agar x > 5:
92
+ ... likho("Sab badiya!")
93
+ ...
94
+ Sab badiya!
95
+ ```
96
+
97
+ ### 4. Transpile Mode (Source-to-Source)
98
+ Inspect the transpiled standard Python code:
99
+ ```bash
100
+ python flavour.py transpile examples/fizzbuzz.mypy
101
+ ```
102
+
103
+ ---
104
+
105
+ ## βš™οΈ Mini-PVM Instruction Set (Opcodes)
106
+
107
+ | Opcode | Argument | Description | Stack Effect |
108
+ | :--- | :--- | :--- | :--- |
109
+ | `LOAD_CONST` | `value` | Push constant onto operand stack | `[] -> [value]` |
110
+ | `LOAD_NAME` | `var_name` | Load variable value from environment | `[] -> [val]` |
111
+ | `STORE_NAME` | `var_name` | Pop top of stack and store in variable | `[val] -> []` |
112
+ | `BINARY_ADD` | - | Pop two operands, add them, push result | `[a, b] -> [a + b]` |
113
+ | `BINARY_SUB` | - | Pop two operands, subtract, push result | `[a, b] -> [a - b]` |
114
+ | `BINARY_MUL` | - | Pop two operands, multiply, push result | `[a, b] -> [a * b]` |
115
+ | `BINARY_DIV` | - | Pop two operands, divide, push result | `[a, b] -> [a / b]` |
116
+ | `BINARY_MOD` | - | Pop two operands, modulo, push result | `[a, b] -> [a % b]` |
117
+ | `COMPARE_OP` | `operator` | Pop two operands, compare (`<`, `>`, `==`, etc.) | `[a, b] -> [bool]` |
118
+ | `POP_JUMP_IF_FALSE`| `target_ip` | Pop top; if `False`, jump instruction pointer to `target_ip` | `[cond] -> []` |
119
+ | `JUMP_ABSOLUTE` | `target_ip` | Unconditionally jump `IP` to `target_ip` | `[] -> []` |
120
+ | `CALL_BUILTIN` | `(func, count)`| Call built-in helper (`str`, `int`, `len`, etc.) | `[args...] -> [res]` |
121
+ | `PRINT_VALUE` | - | Pop top of stack and print to console | `[val] -> []` |
122
+ | `HALT` | - | Terminate virtual machine execution | - |
123
+
124
+ ---
125
+
126
+ ## πŸ“– Keyword Cheat Sheet
127
+
128
+ | Hinglish Keyword | Standard Python | Meaning / Usage |
129
+ | :--- | :--- | :--- |
130
+ | `agar` | `if` | Conditional branch |
131
+ | `warna_agar` | `elif` | Else-if branch |
132
+ | `warna` | `else` | Else fallback |
133
+ | `jabtak` | `while` | While loop |
134
+ | `har` $\dots$ `mein` | `for` $\dots$ `in` | For loop over iterable |
135
+ | `ginte` / `ginti` | `range` | Range generator |
136
+ | `likho` / `batao` | `print` | Output print statement |
137
+ | `sahi` | `True` | Boolean true |
138
+ | `galat` | `False` | Boolean false |
139
+ | `shunya` | `None` | Null / None |
140
+
141
+ ---
142
+
143
+ ## πŸ“ Project Structure
144
+
145
+ ```
146
+ flavour/
147
+ β”œβ”€β”€ pvm/
148
+ β”‚ β”œβ”€β”€ opcodes.py # Opcode definitions and Instruction data classes
149
+ β”‚ β”œβ”€β”€ lexer.py # Tokenizer converting source to typed tokens
150
+ β”‚ β”œβ”€β”€ parser.py # Recursive descent AST parser
151
+ β”‚ β”œβ”€β”€ compiler.py # Bytecode generator with jump backpatching
152
+ β”‚ β”œβ”€β”€ vm.py # Stack-based Mini-PVM execution engine
153
+ β”‚ └── disassembler.py # Bytecode formatter (like Python's 'dis' module)
154
+ β”œβ”€β”€ flavour.py # Unified CLI (run, dis, transpile, repl)
155
+ β”œβ”€β”€ dialects.py # Keyword dictionaries (Hinglish, Gen-Z)
156
+ β”œβ”€β”€ test_pvm.py # Unit tests for the Virtual Machine & Compiler
157
+ β”œβ”€β”€ test_flavour.py # Unit tests for the Transpiler
158
+ β”œβ”€β”€ README.md # Documentation & presentation guide
159
+ └── examples/
160
+ β”œβ”€β”€ loop.mypy # While-loop accumulator on Mini-PVM
161
+ β”œβ”€β”€ branch.mypy # Multi-branch conditionals (agar/warna_agar/warna)
162
+ β”œβ”€β”€ calc.mypy # Arithmetic calculator and expressions
163
+ └── fizzbuzz.mypy # Range-based loops and modulo logic
164
+ ```
165
+
166
+ ---
167
+
168
+ ## πŸ§ͺ Running the Tests
169
+
170
+ To verify both the Virtual Machine and Transpiler suites:
171
+
172
+ ```bash
173
+ python3 test_pvm.py -v && python3 test_flavour.py -v
174
+ ```
175
+
176
+ All 18 tests verify tokenization, AST generation, jump address calculation, stack arithmetic, loop execution, and disassembly.
@@ -0,0 +1,165 @@
1
+ # 🌢️ Flavour: Custom-Keyword Python Dialect & Virtual Machine (Mini-PVM)
2
+
3
+ > **A custom vernacular Python dialect featuring an authentic Stack-Based Virtual Machine (Mini-PVM), Bytecode Compiler with Jump Backpatching, Disassembler, and Source Transpiler.**
4
+
5
+ Flavour allows developers to write code using custom vernacular keywordsβ€”such as **Hinglish** (`agar`, `warna`, `jabtak`, `likho`, `har`, `mein`) or **Gen-Z** (`lowkey`, `deadass`, `spin`, `spill`).
6
+
7
+ Unlike simple text-replacement tools, Flavour provides a **genuine Stack-Based Bytecode Virtual Machine (Mini-PVM)** that compiles source code into low-level bytecode instructions and executes them on an evaluation stackβ€”mirroring how CPython's `ceval.c` works.
8
+
9
+ ---
10
+
11
+ ## πŸ›οΈ System Architecture
12
+
13
+ ```mermaid
14
+ flowchart TD
15
+ A[".mypy Source Code (Hinglish / Gen-Z)"] --> B["Lexer (Tokenizer)"]
16
+ B --> C["Recursive Descent Parser (AST)"]
17
+ C --> D["Bytecode Compiler (Jump Backpatching)"]
18
+ D --> E["Bytecode Instructions (Opcodes + Args)"]
19
+
20
+ subgraph PVM ["Mini-PVM (Stack-Based Virtual Machine)"]
21
+ F["Instruction Pointer (IP)"]
22
+ G["Operand Stack"]
23
+ H["Frame Environment (Symbol Table)"]
24
+ E --> F
25
+ F --> I["Fetch -> Decode -> Execute Loop"]
26
+ I <--> G
27
+ I <--> H
28
+ I --> J["Console Output"]
29
+ end
30
+
31
+ E --> K["Bytecode Disassembler ('dis')"]
32
+ A -.-> L["Transpiler Mode (Optional exec)"]
33
+ ```
34
+
35
+ ---
36
+
37
+ ## ⚑ Quick Start
38
+
39
+ Zero external dependenciesβ€”uses 100% standard Python 3!
40
+
41
+ ### 1. Execute Directly on the Mini-PVM
42
+ ```bash
43
+ python flavour.py examples/loop.mypy
44
+ ```
45
+ ```bash
46
+ python flavour.py examples/fizzbuzz.mypy
47
+ ```
48
+
49
+ ### 2. Disassemble and View Bytecode (The PVM Inspector)
50
+ Shows the compiled instruction stream, opcodes, and jump target addresses:
51
+ ```bash
52
+ python flavour.py dis examples/loop.mypy
53
+ ```
54
+ ```text
55
+ ADDR OPCODE ARGUMENT / TARGET
56
+ -------------------------------------------------------
57
+ 0000 LOAD_CONST '=== Mini-PVM While Loop Demo ==='
58
+ 0001 PRINT_VALUE
59
+ 0002 LOAD_CONST 1
60
+ 0003 STORE_NAME 'ginti'
61
+ 0004 LOAD_CONST 0
62
+ 0005 STORE_NAME 'kul_jod'
63
+ 0006 LOAD_NAME 'ginti'
64
+ 0007 LOAD_CONST 5
65
+ 0008 COMPARE_OP '<='
66
+ 0009 POP_JUMP_IF_FALSE to 0029
67
+ ...
68
+ 0028 JUMP_ABSOLUTE to 0006
69
+ 0029 LOAD_CONST '--- Loop Completed ---'
70
+ 0030 PRINT_VALUE
71
+ 0036 HALT
72
+ ```
73
+
74
+ ### 3. Launch the Interactive REPL on Mini-PVM
75
+ ```bash
76
+ python flavour.py repl
77
+ ```
78
+ ```python
79
+ >>> x = 10
80
+ >>> agar x > 5:
81
+ ... likho("Sab badiya!")
82
+ ...
83
+ Sab badiya!
84
+ ```
85
+
86
+ ### 4. Transpile Mode (Source-to-Source)
87
+ Inspect the transpiled standard Python code:
88
+ ```bash
89
+ python flavour.py transpile examples/fizzbuzz.mypy
90
+ ```
91
+
92
+ ---
93
+
94
+ ## βš™οΈ Mini-PVM Instruction Set (Opcodes)
95
+
96
+ | Opcode | Argument | Description | Stack Effect |
97
+ | :--- | :--- | :--- | :--- |
98
+ | `LOAD_CONST` | `value` | Push constant onto operand stack | `[] -> [value]` |
99
+ | `LOAD_NAME` | `var_name` | Load variable value from environment | `[] -> [val]` |
100
+ | `STORE_NAME` | `var_name` | Pop top of stack and store in variable | `[val] -> []` |
101
+ | `BINARY_ADD` | - | Pop two operands, add them, push result | `[a, b] -> [a + b]` |
102
+ | `BINARY_SUB` | - | Pop two operands, subtract, push result | `[a, b] -> [a - b]` |
103
+ | `BINARY_MUL` | - | Pop two operands, multiply, push result | `[a, b] -> [a * b]` |
104
+ | `BINARY_DIV` | - | Pop two operands, divide, push result | `[a, b] -> [a / b]` |
105
+ | `BINARY_MOD` | - | Pop two operands, modulo, push result | `[a, b] -> [a % b]` |
106
+ | `COMPARE_OP` | `operator` | Pop two operands, compare (`<`, `>`, `==`, etc.) | `[a, b] -> [bool]` |
107
+ | `POP_JUMP_IF_FALSE`| `target_ip` | Pop top; if `False`, jump instruction pointer to `target_ip` | `[cond] -> []` |
108
+ | `JUMP_ABSOLUTE` | `target_ip` | Unconditionally jump `IP` to `target_ip` | `[] -> []` |
109
+ | `CALL_BUILTIN` | `(func, count)`| Call built-in helper (`str`, `int`, `len`, etc.) | `[args...] -> [res]` |
110
+ | `PRINT_VALUE` | - | Pop top of stack and print to console | `[val] -> []` |
111
+ | `HALT` | - | Terminate virtual machine execution | - |
112
+
113
+ ---
114
+
115
+ ## πŸ“– Keyword Cheat Sheet
116
+
117
+ | Hinglish Keyword | Standard Python | Meaning / Usage |
118
+ | :--- | :--- | :--- |
119
+ | `agar` | `if` | Conditional branch |
120
+ | `warna_agar` | `elif` | Else-if branch |
121
+ | `warna` | `else` | Else fallback |
122
+ | `jabtak` | `while` | While loop |
123
+ | `har` $\dots$ `mein` | `for` $\dots$ `in` | For loop over iterable |
124
+ | `ginte` / `ginti` | `range` | Range generator |
125
+ | `likho` / `batao` | `print` | Output print statement |
126
+ | `sahi` | `True` | Boolean true |
127
+ | `galat` | `False` | Boolean false |
128
+ | `shunya` | `None` | Null / None |
129
+
130
+ ---
131
+
132
+ ## πŸ“ Project Structure
133
+
134
+ ```
135
+ flavour/
136
+ β”œβ”€β”€ pvm/
137
+ β”‚ β”œβ”€β”€ opcodes.py # Opcode definitions and Instruction data classes
138
+ β”‚ β”œβ”€β”€ lexer.py # Tokenizer converting source to typed tokens
139
+ β”‚ β”œβ”€β”€ parser.py # Recursive descent AST parser
140
+ β”‚ β”œβ”€β”€ compiler.py # Bytecode generator with jump backpatching
141
+ β”‚ β”œβ”€β”€ vm.py # Stack-based Mini-PVM execution engine
142
+ β”‚ └── disassembler.py # Bytecode formatter (like Python's 'dis' module)
143
+ β”œβ”€β”€ flavour.py # Unified CLI (run, dis, transpile, repl)
144
+ β”œβ”€β”€ dialects.py # Keyword dictionaries (Hinglish, Gen-Z)
145
+ β”œβ”€β”€ test_pvm.py # Unit tests for the Virtual Machine & Compiler
146
+ β”œβ”€β”€ test_flavour.py # Unit tests for the Transpiler
147
+ β”œβ”€β”€ README.md # Documentation & presentation guide
148
+ └── examples/
149
+ β”œβ”€β”€ loop.mypy # While-loop accumulator on Mini-PVM
150
+ β”œβ”€β”€ branch.mypy # Multi-branch conditionals (agar/warna_agar/warna)
151
+ β”œβ”€β”€ calc.mypy # Arithmetic calculator and expressions
152
+ └── fizzbuzz.mypy # Range-based loops and modulo logic
153
+ ```
154
+
155
+ ---
156
+
157
+ ## πŸ§ͺ Running the Tests
158
+
159
+ To verify both the Virtual Machine and Transpiler suites:
160
+
161
+ ```bash
162
+ python3 test_pvm.py -v && python3 test_flavour.py -v
163
+ ```
164
+
165
+ All 18 tests verify tokenization, AST generation, jump address calculation, stack arithmetic, loop execution, and disassembly.
@@ -0,0 +1,108 @@
1
+ """
2
+ Dialect Keyword Mappings for Python 'Flavour'.
3
+
4
+ Defines keyword translations from custom vernacular dialects
5
+ (e.g., Hinglish, Gen-Z) to standard Python keywords and built-in functions.
6
+ """
7
+
8
+ HINGLISH_MAP = {
9
+ # Control Flow
10
+ "agar": "if",
11
+ "warna_agar": "elif",
12
+ "warna": "else",
13
+ "jabtak": "while",
14
+ "har": "for",
15
+ "mein": "in",
16
+ "ruko": "break",
17
+ "aage": "continue",
18
+ "pass_karo": "pass",
19
+
20
+ # Functions & Classes
21
+ "kaam": "def",
22
+ "wapas": "return",
23
+ "varg": "class",
24
+
25
+ # Exception Handling
26
+ "koshish": "try",
27
+ "pakdo": "except",
28
+ "aakhirkar": "finally",
29
+ "phenko": "raise",
30
+
31
+ # Logical & Boolean
32
+ "sahi": "True",
33
+ "galat": "False",
34
+ "shunya": "None",
35
+ "khali": "None",
36
+ "aur": "and",
37
+ "ya": "or",
38
+ "nahi": "not",
39
+ "hai": "is",
40
+
41
+ # Import / Context
42
+ "le_aao": "import",
43
+ "se": "from",
44
+ "saath": "with",
45
+ "jaise": "as",
46
+
47
+ # Common Built-ins
48
+ "likho": "print",
49
+ "batao": "print",
50
+ "bolo": "print",
51
+ "pucho": "input",
52
+ "ginti": "range",
53
+ "ginte": "range",
54
+ "lambai": "len",
55
+ "jodo": "sum",
56
+ }
57
+
58
+ GENZ_MAP = {
59
+ # Control Flow
60
+ "lowkey": "if",
61
+ "highkey": "elif",
62
+ "deadass": "else",
63
+ "spin": "while",
64
+ "vibe": "for",
65
+ "wit": "in",
66
+ "period": "break",
67
+ "pass_it": "continue",
68
+ "ghost": "pass",
69
+
70
+ # Functions & Return
71
+ "flex": "def",
72
+ "bop": "return",
73
+ "squad": "class",
74
+
75
+ # Exception Handling
76
+ "vibe_check": "try",
77
+ "catch_hands": "except",
78
+ "yeet": "raise",
79
+
80
+ # Logical & Boolean
81
+ "fr": "True",
82
+ "no_cap": "True",
83
+ "cap": "False",
84
+ "sus": "None",
85
+ "and_that": "and",
86
+ "or_nah": "or",
87
+ "nah": "not",
88
+
89
+ # Common Built-ins
90
+ "spill": "print",
91
+ "listen": "input",
92
+ "count": "range",
93
+ "size": "len",
94
+ }
95
+
96
+ DIALECTS = {
97
+ "hinglish": HINGLISH_MAP,
98
+ "genz": GENZ_MAP,
99
+ }
100
+
101
+ def get_dialect(name: str = "hinglish") -> dict:
102
+ """Retrieve dialect keyword mapping by name (case-insensitive)."""
103
+ normalized = name.strip().lower()
104
+ if normalized not in DIALECTS:
105
+ available = ", ".join(repr(k) for k in DIALECTS)
106
+ raise ValueError(f"Unknown dialect '{name}'. Available: {available}")
107
+ return DIALECTS[normalized]
108
+