Coder Social home page Coder Social logo

purplemyst / epython Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 1.0 98 KB

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

License: GNU General Public License v3.0

Elixir 89.15% Python 10.85%
bytecode elixir cpython python interpreters

epython's Issues

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.

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, ...)

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

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)

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.

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.