Giter VIP home page Giter VIP logo

epython's Introduction

EPython

EPython is be a toy CPython bytecode interpreter written in Elixir.

Compiliation

To utilize EPython, you will need the Erlang VM and mix. This README assumes you're utilizing an unix-like operating system, such as Linux or OSX, due to this being not tested on Windows at all.

You can install everything by following the instructions on the official Elixir website.

Then, to compile, you can type this into your shell:

$ MIX_ENV=prod mix escript.build

This will generate an epython executable in the main project directory which you can pass python files to (actual python files, not just bytecode files) as a command-line argument.

Running tests

You can run a variety of tests for the interpreter itself by running ./run_tests.py.

epython's People

Contributors

carlbordum avatar purplemyst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

carlbordum

epython's Issues

Import system

Adding an import system is important, due to it being one of python's biggest strengths.

  • Basic module support (variables, functions, ...)
  • Module-specific variables (__name__, ...)
  • Builtin modules (math, ...)
  • OS-specific modules (os, sys, ...)

Proper function making/calls

Currently function calls are limited to positionary arguments with no default values. Here are some features that need to be implemented:

  • Default arguments
  • Keyword arguments
  • Variadic positional arguments
  • Variadic keyword arguments

Hard crash handling

(Note: A hard crash is when the interpreter crashes, rather than the Python code crashing.)

It might be useful to print the line of CPython bytecode, the line of Python code, and stack/frames in the case of an unhandled interpreter crash.

OO support

OO support is a critical part of Python.

  • Basic object support (classes)
  • Magic class methods (__init__ etc)
  • Types
  • First-class object support (everything is an object)
  • Slotted objects

And so on.

Argument counts are not validated

def add(a, b):
    print(a + b)

add(1, 2, 3)

This prints 3, when it should error.

Additionally:

def a(x, y):
        print(x * 1)

a(3)

This also prints 3.

Crash on // division

** (KeyError) key :pc not found in: %EPython.InterpreterState{next_id: 0, objects: %{}, refcounts: %{}, topframe: %EPython.PyFrame{blocks: [], code: [argcount: 2, kwonlyargcount: 0, nlocals: 2, stacksize: 3, flags: 67, code: <<116, 0, 124, 0, 124, 1, 26, 0, 131, 1, 1, 0, 100, 0, 83, 0>>, consts: {:none}, names: {"print"}, varnames: {"x", "y"}, freevars: {}, cellvars: {}, filename: "test.py", name: "a", firstlineno: 1, lnotab: <<0, 1>>], pc: 8, previous_frame: %EPython.PyFrame{blocks: [], code: [argcount: 0, kwonlyargcount: 0, nlocals: 0, stacksize: 3, flags: 64, code: <<100, 0, 100, 1, 132, 0, 90, 0, 101, 0, 100, 2, 100, 3, 131, 2, 1, 0, 100, 4, 83, 0>>, consts: {[argcount: 2, kwonlyargcount: 0, nlocals: 2, stacksize: 3, flags: 67, code: <<116, 0, 124, 0, 124, 1, 26, 0, 131, 1, 1, 0, 100, 0, 83, 0>>, consts: {:none}, names: {"print"}, varnames: {"x", "y"}, freevars: {}, cellvars: {}, filename: "test.py", name: "a", firstlineno: 1, lnotab: <<0, 1>>], "a", 1, 2, :none}, names: {"a"}, varnames: {}, freevars: {}, cellvars: {}, filename: "test.py", name: "<module>", firstlineno: 1, lnotab: <<8, 3>>], pc: 16, previous_frame: nil, stack: [], variables: %{"a" => %EPython.PyUserFunction{code: [argcount: 2, kwonlyargcount: 0, nlocals: 2, stacksize: 3, flags: 67, code: <<116, 0, 124, 0, 124, 1, 26, 0, 131, 1, 1, 0, 100, 0, 83, 0>>, consts: {:none}, names: {"print"}, varnames: {"x", "y"}, freevars: {}, cellvars: {}, filename: "test.py", name: "a", firstlineno: 1, lnotab: <<0, 1>>], name: "a"}}}, stack: [0.0, %EPython.PyBuiltinFunction{function: #Function<0.22053186/2 in EPython.Interpreter.builtins/0>, name: "print"}], variables: %{"x" => 1, "y" => 2}}}
    (epython) lib/epython/interpreter.ex:163: EPython.Interpreter.execute_instructions/1
    (elixir) lib/kernel/cli.ex:105: anonymous fn/3 in Kernel.CLI.exec_fun/2

Code:

print(3 // 2)

Exception handling

Exception handling is a pretty key concept. This is a tracking issue for everything related to it.

  • Being able to throw exceptions and unwind the stack
  • try/except statements
  • Exception objects and hierachy
  • User-defined exceptions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.