Skip to content
/ py_vm Public

Implements a toy python vm with a few basic operations.

Notifications You must be signed in to change notification settings

cshintov/py_vm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A toy python vm with a few basic operations

This basic python vm written in Python implements basic arithmetic operations and function call. These are just a small subset of operations that the actual CPython implements. The input to this VM is Python bytecode.

By executing a series of stack operations this tiny VM executes the bytecode and produces the intended result. Just like the official implementation in C, the operations are decided by a switch on OPCODEs found in the bytecode. Because of the absence of the switch in Python, I have used a very helpful OPMAP (operations) dictionary to do the job.

The stack operations are roughly as follows:

1. Push OPERANDS to stack.
2. When OPCODE is encountered, POP the corresponding number of OPERANDS. 
3. Do the associated operation. 
4. Push the result back.

Note:

This project originally was here: 
https://github.com/cshintov/python/tree/master/projects/python_vm

About

Implements a toy python vm with a few basic operations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages