@lewin671/python-vm 0.1.0 → 0.1.2
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.
- package/README.md +1 -2
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js.map +1 -0
- package/dist/compiler_module/compiler.d.ts.map +1 -0
- package/dist/compiler_module/compiler.js.map +1 -0
- package/dist/compiler_module/index.d.ts.map +1 -0
- package/dist/compiler_module/index.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/lexer/index.d.ts.map +1 -0
- package/dist/lexer/index.js.map +1 -0
- package/dist/lexer/lexer.d.ts.map +1 -0
- package/dist/lexer/lexer.js.map +1 -0
- package/dist/parser/expressions.d.ts.map +1 -0
- package/dist/parser/expressions.js.map +1 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/statements.d.ts.map +1 -0
- package/dist/parser/statements.js.map +1 -0
- package/dist/parser/targets.d.ts.map +1 -0
- package/dist/parser/targets.js.map +1 -0
- package/dist/types/ast.d.ts.map +1 -0
- package/dist/types/ast.js.map +1 -0
- package/dist/types/bytecode.d.ts.map +1 -0
- package/dist/types/bytecode.js.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/token.d.ts.map +1 -0
- package/dist/types/token.js.map +1 -0
- package/dist/vm/builtins.d.ts.map +1 -0
- package/dist/vm/builtins.js.map +1 -0
- package/dist/vm/callable.d.ts.map +1 -0
- package/dist/vm/callable.js.map +1 -0
- package/dist/vm/execution.d.ts.map +1 -0
- package/dist/vm/execution.js.map +1 -0
- package/dist/vm/expression-generator.d.ts.map +1 -0
- package/dist/vm/expression-generator.js.map +1 -0
- package/dist/vm/expressions.d.ts.map +1 -0
- package/dist/vm/expressions.js.map +1 -0
- package/dist/vm/imports.d.ts.map +1 -0
- package/dist/vm/imports.js.map +1 -0
- package/dist/vm/index.d.ts.map +1 -0
- package/dist/vm/index.js.map +1 -0
- package/dist/vm/operations.d.ts.map +1 -0
- package/dist/vm/operations.js.map +1 -0
- package/dist/vm/runtime-types.d.ts.map +1 -0
- package/dist/vm/runtime-types.js.map +1 -0
- package/dist/vm/statements.d.ts.map +1 -0
- package/dist/vm/statements.js.map +1 -0
- package/dist/vm/truthy.d.ts.map +1 -0
- package/dist/vm/truthy.js.map +1 -0
- package/dist/vm/value-utils.d.ts.map +1 -0
- package/dist/vm/value-utils.js.map +1 -0
- package/dist/vm/vm.d.ts.map +1 -0
- package/dist/vm/vm.js.map +1 -0
- package/package.json +7 -1
- package/.claude/settings.local.json +0 -3
- package/.prettierrc +0 -7
- package/Agents.md +0 -66
- package/SETUP.md +0 -171
- package/examples/assert_testing.py +0 -38
- package/examples/big_int_precision.py +0 -2
- package/examples/boolean_logic.py +0 -35
- package/examples/break_continue.py +0 -43
- package/examples/classes_objects.py +0 -43
- package/examples/compiler_killer_async.py +0 -6
- package/examples/compiler_killer_bigint.py +0 -3
- package/examples/compiler_killer_bool_int_dict_key.py +0 -5
- package/examples/compiler_killer_bool_len.py +0 -9
- package/examples/compiler_killer_floor_division.py +0 -4
- package/examples/compiler_killer_is_identity.py +0 -3
- package/examples/compiler_killer_list_sort_return.py +0 -3
- package/examples/compiler_killer_match.py +0 -13
- package/examples/compiler_killer_negative_repeat.py +0 -3
- package/examples/compiler_killer_negative_zero_repr.py +0 -3
- package/examples/compiler_killer_rounding.py +0 -4
- package/examples/compiler_killer_slice_assign.py +0 -3
- package/examples/comprehensions.py +0 -28
- package/examples/conditions.py +0 -13
- package/examples/context_manager.py +0 -35
- package/examples/decorators.py +0 -50
- package/examples/exceptions.py +0 -40
- package/examples/fibonacci.py +0 -10
- package/examples/functions.py +0 -38
- package/examples/generator.py +0 -51
- package/examples/global_nonlocal.py +0 -48
- package/examples/hello.py +0 -3
- package/examples/itertools_example.py +0 -33
- package/examples/lists_dicts.py +0 -29
- package/examples/loops.py +0 -19
- package/examples/math_ops.py +0 -15
- package/examples/nan_set.py +0 -6
- package/examples/numbers_operators.py +0 -51
- package/examples/sets.py +0 -36
- package/examples/slicing.py +0 -29
- package/examples/starred_unpacking.py +0 -3
- package/examples/string_formatting.py +0 -36
- package/examples/strings.py +0 -22
- package/examples/tuples.py +0 -45
- package/examples/type_conversion.py +0 -41
- package/jest.config.js +0 -15
- package/notes/iterations/compiler-runtime/compiler-runtime_2025-09-16.md +0 -25
- package/notes/iterations/compiler-runtime/compiler-runtime_2026-01-16.md +0 -24
- package/notes/iterations/compiler-runtime/compiler-runtime_test_2026-01-16.md +0 -21
- package/notes/iterations/floor-division/floor-division_2026-01-16.md +0 -29
- package/prompts/commit.txt +0 -9
- package/prompts/task.txt +0 -21
- package/prompts/test.txt +0 -23
- package/scripts/codex-loop.js +0 -215
- package/scripts/verify.sh +0 -12
- package/src/compiler.ts +0 -58
- package/src/compiler_module/compiler.ts +0 -19
- package/src/compiler_module/index.ts +0 -1
- package/src/index.ts +0 -39
- package/src/lexer/index.ts +0 -1
- package/src/lexer/lexer.ts +0 -402
- package/src/parser/expressions.ts +0 -462
- package/src/parser/index.ts +0 -1
- package/src/parser/parser.ts +0 -102
- package/src/parser/statements.ts +0 -366
- package/src/parser/targets.ts +0 -71
- package/src/types/ast.ts +0 -64
- package/src/types/bytecode.ts +0 -50
- package/src/types/index.ts +0 -3
- package/src/types/token.ts +0 -44
- package/src/vm/builtins.ts +0 -237
- package/src/vm/callable.ts +0 -154
- package/src/vm/execution.ts +0 -251
- package/src/vm/expression-generator.ts +0 -65
- package/src/vm/expressions.ts +0 -373
- package/src/vm/imports.ts +0 -61
- package/src/vm/index.ts +0 -2
- package/src/vm/operations.ts +0 -414
- package/src/vm/runtime-types.ts +0 -292
- package/src/vm/statements.ts +0 -358
- package/src/vm/truthy.ts +0 -36
- package/src/vm/value-utils.ts +0 -173
- package/src/vm/vm.ts +0 -80
- package/tests/compiler.test.ts +0 -111
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -16
package/tests/compiler.test.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { PythonCompiler } from '../src/index';
|
|
2
|
-
import { execFileSync } from 'child_process';
|
|
3
|
-
import * as fs from 'fs';
|
|
4
|
-
import * as path from 'path';
|
|
5
|
-
|
|
6
|
-
const pythonCommandCandidates = [
|
|
7
|
-
process.env.PYTHON,
|
|
8
|
-
'python3',
|
|
9
|
-
'python',
|
|
10
|
-
].filter(Boolean) as string[];
|
|
11
|
-
|
|
12
|
-
const runPythonFile = (filePath: string): string => {
|
|
13
|
-
const errors: { cmd: string; error: string }[] = [];
|
|
14
|
-
|
|
15
|
-
for (const cmd of pythonCommandCandidates) {
|
|
16
|
-
try {
|
|
17
|
-
return execFileSync(cmd, [filePath], { encoding: 'utf8' });
|
|
18
|
-
} catch (error) {
|
|
19
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
20
|
-
errors.push({ cmd, error: errorMsg });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const errorDetails = errors
|
|
25
|
-
.map(({ cmd, error }) => ` • ${cmd}: ${error}`)
|
|
26
|
-
.join('\n');
|
|
27
|
-
|
|
28
|
-
throw new Error(
|
|
29
|
-
`❌ Python interpreter not found\n\n` +
|
|
30
|
-
`Attempted commands:\n${errorDetails}\n\n` +
|
|
31
|
-
`Please ensure Python 3 is installed and in your PATH, or set the PYTHON environment variable.`
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const captureOutput = (fn: () => void): string => {
|
|
36
|
-
const outputChunks: string[] = [];
|
|
37
|
-
const originalWrite = process.stdout.write;
|
|
38
|
-
|
|
39
|
-
process.stdout.write = ((chunk: any) => {
|
|
40
|
-
const normalized =
|
|
41
|
-
typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
42
|
-
outputChunks.push(normalized);
|
|
43
|
-
return true;
|
|
44
|
-
}) as any;
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
fn();
|
|
48
|
-
} finally {
|
|
49
|
-
process.stdout.write = originalWrite;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return outputChunks.join('');
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
describe('PythonCompiler - Public API Tests', () => {
|
|
56
|
-
let compiler: PythonCompiler;
|
|
57
|
-
|
|
58
|
-
beforeEach(() => {
|
|
59
|
-
compiler = new PythonCompiler();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('runFile() method', () => {
|
|
63
|
-
const examplesDir = path.join(__dirname, '../examples');
|
|
64
|
-
const exampleFiles = fs
|
|
65
|
-
.readdirSync(examplesDir)
|
|
66
|
-
.filter((file) => file.endsWith('.py'))
|
|
67
|
-
.sort();
|
|
68
|
-
|
|
69
|
-
it('should match output for example files', () => {
|
|
70
|
-
const failedTests: Array<{ file: string; expected: string; actual: string }> = [];
|
|
71
|
-
|
|
72
|
-
for (const fileName of exampleFiles) {
|
|
73
|
-
const filePath = path.join(examplesDir, fileName);
|
|
74
|
-
const expectedOutput = runPythonFile(filePath);
|
|
75
|
-
const actualOutput = captureOutput(() => {
|
|
76
|
-
compiler.runFile(filePath);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
if (actualOutput !== expectedOutput) {
|
|
80
|
-
failedTests.push({
|
|
81
|
-
file: fileName,
|
|
82
|
-
expected: expectedOutput,
|
|
83
|
-
actual: actualOutput,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (failedTests.length > 0) {
|
|
89
|
-
const failureDetails = failedTests
|
|
90
|
-
.map(({ file, expected, actual }) => {
|
|
91
|
-
return (
|
|
92
|
-
`\n📄 ${file}\n` +
|
|
93
|
-
` Expected:\n${expected
|
|
94
|
-
.split('\n')
|
|
95
|
-
.map((l) => ` ${l}`)
|
|
96
|
-
.join('\n')}\n` +
|
|
97
|
-
` Actual:\n${actual
|
|
98
|
-
.split('\n')
|
|
99
|
-
.map((l) => ` ${l}`)
|
|
100
|
-
.join('\n')}`
|
|
101
|
-
);
|
|
102
|
-
})
|
|
103
|
-
.join('\n');
|
|
104
|
-
|
|
105
|
-
throw new Error(
|
|
106
|
-
`❌ ${failedTests.length} test(s) failed:${failureDetails}`
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"declaration": true,
|
|
14
|
-
"declarationMap": true,
|
|
15
|
-
"sourceMap": true,
|
|
16
|
-
"moduleResolution": "node"
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*"],
|
|
19
|
-
"exclude": ["node_modules", "dist", "tests"]
|
|
20
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config';
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
test: {
|
|
5
|
-
globals: true,
|
|
6
|
-
environment: 'node',
|
|
7
|
-
include: ['tests/**/*.test.ts'],
|
|
8
|
-
coverage: {
|
|
9
|
-
provider: 'v8',
|
|
10
|
-
reporter: ['text', 'json', 'html'],
|
|
11
|
-
include: ['src/**/*.ts'],
|
|
12
|
-
exclude: ['src/**/*.d.ts'],
|
|
13
|
-
},
|
|
14
|
-
testTimeout: 10000,
|
|
15
|
-
},
|
|
16
|
-
});
|