Git Product home page Git Product logo

pyterpreter's Introduction

pyterpreter

Build Status

Python interpreter built on Truffle and Graal VM

Features

Types

  • int (arbitrary precision)
  • str
  • bool

Operators

  • arithmetic (+, -, *, /, %)
  • assignment (=, +=, -=, *=, /=, %=)
  • comparison (==, !=, >, >=, <, <=)
  • logical (not, and, or)

Flow control

  • if/else (no elif)
  • while loop (no for)

Functions

  • function definition, arbitrary argument number (only positional, no named)
  • function nesting, recursion
  • no pass blank statement
  • builtin functions:
    • x = str(arg) - convert arg to string type
    • x = int(arg) - convert arg to int type
    • print(arg) - print arg to console (with newline)
    • x = input() - read user input from console, assign to variable
    • sleep(seconds) - sleep for given number of seconds
    • exit() - exit the program
    • x = time() - get millisecond-precision time
      • Not actual clock time, but good for measuring elapsed time
      • Similar to Python's time.time() but Pyterpreter cannot do imports so there we go
      • For compatibility in running pyterpreter scripts in Python, user a wrapper script where you import time(), e.g. from time import time; import pyterpreter_script.py

Examples

Installation

Requirements

  • JVM (tested on 8)
    • It will work on regular HotspotVM
    • For better performance run on GraalVM (Linux/MAC)
  • Gradle will be used or automatically downloaded when running gradlew (see below)
  • In order to run Pyterpreter on Graal, copy or symlink Graal root directory to pyterpreter/graalvm (download on the same URL as above, but use the links on the top of the page)

Steps

$ git clone [email protected]:melkamar/pyterpreter.git
$ cd pyterpreter
$ ./gradlew clean test jar

Usage

$ ./pyterpreter [args]  # Non-graal
$ ./pyterpreter-graal [args]  # Graal-enabled
  • No arguments - start REPL
  • Single argument - path to file - execute that file
  • -r file/in/resources - run file from inside pyterpreter jar. See resources folder
    • e.g. java -jar build/libs/pyt*all* -r benchmark/fibonacci.py will start fibonacci benchmark.

Numbers

Using benchmark countdown.py, in milliseconds

  • Hotspot 1722/356
  • Graal 2627/438

:(

pyterpreter's People

Contributors

melkamar avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.