__ __ __ __ __ __ ______ __ __ /\ "-./ \ /\ \ /\ "-.\ \ /\ \ /\ == \ /\ \_\ \ \ \ \-./\ \ \ \ \ \ \ \-. \ \ \ \ \ \ _-/ \ \____ \ \ \_\ \ \_\ \ \_\ \ \_\\"\_\ \ \_\ \ \_\ \/\_____\ \/_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_/ \/_____/
A mini python interpreter, vm implemented with ANSI C and compiler implemented with Python 3.
cd minipy
make && make test
# and enjoy yourself ^_^
In /src/python
tmcode.py
bytecode definitionlex.py
lex tokenizerparse.py
handwrite LL parserencode.py
code generator, just runpython encode.py {script.py}
and you will get generated code.
- stack based
- bytecode defined in
src/tmcode.py
- exception handling implemented with setjmp/longjmp
- C function and python function.
- exception traceback
- mark-sweep garbage collection
- tail call optimization
- constant pool
vm.c
entryinterp.c
interpreterbuiltins.c
built-in functionsops.c
operation implementationtmarg.c
handle argumentsexception.c
handle exceptiongc.c
garbage collector and memory management.string.c
string functionsnumber.c
number functionslist.c
list functionsdict.c
dictionary functionsfunction.c
function functions
- string, strings are immutable.
- number, use
double
as default number. - list, array list increase with simple strategy.
- dict, this is not hashtable, for the optimization of global access, because the offset of a variable in
globals
dict never change.Besides, object are implemented in dict. - function, C functions, python functions and methods.
- None, NoneType object.
- data, data are other data structure such as iterator.
MIT