All Projects → ThakeeNathees → pocketlang

ThakeeNathees / pocketlang

Licence: MIT license
A lightweight, fast embeddable scripting language.

Programming Languages

c
50402 projects - #5 most used programming language
python
139335 projects - #7 most used programming language
Batchfile
5799 projects
lua
6591 projects
javascript
184084 projects - #8 most used programming language
Makefile
30231 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to pocketlang

RISVM
A low overhead, embeddable bytecode virtual machine in C++
Stars: ✭ 21 (-98.51%)
Mutual labels:  vm, interpreter
Q3vm
Q3VM - Single file (vm.c) bytecode virtual machine/interpreter for C-language input
Stars: ✭ 585 (-58.57%)
Mutual labels:  vm, interpreter
Eval5
A JavaScript interpreter written in TypeScript - Support ES5
Stars: ✭ 281 (-80.1%)
Mutual labels:  vm, interpreter
retro12
This repo is retired. See http://forthworks.com:8000/
Stars: ✭ 18 (-98.73%)
Mutual labels:  vm, interpreter
Janet
A dynamic language and bytecode vm
Stars: ✭ 2,216 (+56.94%)
Mutual labels:  vm, interpreter
interp
Interpreter experiment. Testing dispatch methods: Switching, Direct/Indirect Threaded Code, Tail-Calls and Inlining
Stars: ✭ 32 (-97.73%)
Mutual labels:  vm, interpreter
Vm.js
Javascript 解释器. Javascript Interpreter
Stars: ✭ 343 (-75.71%)
Mutual labels:  vm, interpreter
RSqueak
A Squeak/Smalltalk VM written in RPython.
Stars: ✭ 78 (-94.48%)
Mutual labels:  vm, interpreter
Javo
🚀 A sandboxed VM any Java developer can afford
Stars: ✭ 144 (-89.8%)
Mutual labels:  vm, interpreter
Quickjs
The official repo is at bellard/quickjs.
Stars: ✭ 1,429 (+1.2%)
Mutual labels:  vm, interpreter
go-jdk
Run JVM-based code in Go efficiently
Stars: ✭ 61 (-95.68%)
Mutual labels:  vm, interpreter
Tagha
Minimal, low-level, fast, and self-contained register-based bytecode virtual machine/runtime environment.
Stars: ✭ 101 (-92.85%)
Mutual labels:  vm, interpreter
snap
An embeddable scripting language inspired by Lua and JavaScript.
Stars: ✭ 32 (-97.73%)
Mutual labels:  vm, interpreter
SandboxJS
Safe eval runtime
Stars: ✭ 18 (-98.73%)
Mutual labels:  vm, interpreter
Animach
Scheme语言实现和运行时环境 / A Scheme runtime & implementation
Stars: ✭ 45 (-96.81%)
Mutual labels:  vm, interpreter
Passerine
A small extensible programming language designed for concise expression with little code.
Stars: ✭ 341 (-75.85%)
Mutual labels:  vm, interpreter
quickjs-build
Build for QuickJS JavaScript Engine
Stars: ✭ 25 (-98.23%)
Mutual labels:  vm, interpreter
AlchemyVM
WebAssembly Virtual Machine Built In Elixir
Stars: ✭ 184 (-86.97%)
Mutual labels:  vm, interpreter
Zetavm
Multi-Language Platform for Dynamic Programming Languages
Stars: ✭ 592 (-58.07%)
Mutual labels:  vm, interpreter
Alchemyvm
WebAssembly Virtual Machine Built In Elixir
Stars: ✭ 176 (-87.54%)
Mutual labels:  vm, interpreter

Pocketlang is a lightweight (~3000 semicolons) and fast object oriented, embeddable scripting language written in C. It has a ruby flavoured python syntax, that can be learned within 15 minutes. Including the compiler, bytecode VM and runtime, it's a standalone executable with zero external dependencies just as it's self descriptive name. The pocketlang VM can be embedded in another hosting program very easily.

Wren Language and their wonderful book Crafting Interpreters were used as a reference to write this language.

What pocketlang looks like

# Python like import statement.
from time import clock as now

# A recursive fibonacci function.
def fib(n)
  if n < 2 then return n end
  return fib(n-1) + fib(n-2)
end

# Prints all fibonacci from 0 to 10 exclusive.
for i in 0..10
  print("fib($i) = ${fib(i)}")
end

Try It Now

You can try pocketlang on your browser. It's a WebAssembly build of the VM compiled using emscripten. Note that in the webassembly version of the language, some features (input, file handling, relative import, etc.) have disabled, has limited memory allocations, and the stdout calls might be slower.

Documentation

The pocketlang documentation is hosted at https://thakeenathees.github.io/pocketlang/ which is built from the docs branch generated by a little python script at docs/generate.py. Note that the documentations are WIP and might not be up to date.

Performance

Pocketlang uses NaN-Boxing which is a memory efficient way to represent dynamic types and dealing with them are much faster. It supports tail call optimization. When a function returns a call, the callee can re-use the caller's stack frame, this will optimize memory from O(n) to O(1) and for tail recursive it'll completely prevent stackoverflows and yet it's faster.

All benchmarks below were executed on: Windows10 (64bit), ASUS N552VX, Intel Core i7-6700HQ 2.6GHz with 12GB SODIMM Ram. And the language versions are: pocketlang (pre-alpha), wren v0.3.0, python v3.7.4, ruby v2.7.2.

performance

The source files used to run benchmarks can be found at test/benchmarks/ directory. They were executed using a small python script in the test directory.

Building From Source

It can be build from source easily without any dependencies, or additional requirements except for a c99 compatible compiler. It can be compiled with the following command.

GCC / MinGw / Clang (alias with gcc)

gcc -o pocket cli/*.c src/core/*.c src/libs/*.c -Isrc/include -lm -ldl

MSVC

cl /Fepocket cli/*.c src/core/*.c src/libs/*.c /Isrc/include && rm *.obj

Makefile

make

To run the make file on windows with mingw, you require the GNU make tool which you can get from msys2 or cygwin.

Windows batch script

scripts\build.bat

You don't have to run the script from a Visual Studio .NET developer command prompt, It'll search for the MSVS installation path and setup the build environment.

For other compiler/IDE

  1. Create an empty project file / makefile.
  2. Add all C files in the src/core/ directory.
  3. Add all C files in the src/libs/ directory.
  4. Add all C files in the cli/ directory.
  5. Add src/include to include path.
  6. If *nix link m, dl
  7. Compile.

Visual studio project files can be generated with the premake, see scripts/README for more information. If you weren't able to compile it, please report us by opening an issue.

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].