All Projects → BlueBlazin → thislang

BlueBlazin / thislang

Licence: MIT license
A subset of javascript implemented in that subset of javascript. Yes, it can run itself.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to thislang

Arturo
Simple, expressive & portable programming language for efficient scripting
Stars: ✭ 225 (+625.81%)
Mutual labels:  interpreter, virtual-machine
Tagha
Minimal, low-level, fast, and self-contained register-based bytecode virtual machine/runtime environment.
Stars: ✭ 101 (+225.81%)
Mutual labels:  interpreter, virtual-machine
Openj9
Eclipse OpenJ9: A Java Virtual Machine for OpenJDK that's optimized for small footprint, fast start-up, and high throughput. Builds on Eclipse OMR (https://github.com/eclipse/omr) and combines with the Extensions for OpenJDK for OpenJ9 repo.
Stars: ✭ 2,802 (+8938.71%)
Mutual labels:  interpreter, virtual-machine
Go.vm
A simple virtual machine - compiler & interpreter - written in golang
Stars: ✭ 178 (+474.19%)
Mutual labels:  interpreter, virtual-machine
Laythe
A gradually typed language originally based on the crafting interpreters series
Stars: ✭ 58 (+87.1%)
Mutual labels:  interpreter, virtual-machine
Cub
The Cub Programming Language
Stars: ✭ 198 (+538.71%)
Mutual labels:  interpreter, virtual-machine
LLVM-JVM
[W.I.P] A Just-In-Time Java Virtual Machine written in Haskell
Stars: ✭ 22 (-29.03%)
Mutual labels:  interpreter, virtual-machine
Quickjs
The official repo is at bellard/quickjs.
Stars: ✭ 1,429 (+4509.68%)
Mutual labels:  interpreter, virtual-machine
ciao
Ciao is a modern Prolog implementation that builds up from a logic-based simple kernel designed to be portable, extensible, and modular.
Stars: ✭ 190 (+512.9%)
Mutual labels:  interpreter, virtual-machine
Freeze-OS
An Operating System that runs on top of an interpreter.
Stars: ✭ 24 (-22.58%)
Mutual labels:  interpreter, virtual-machine
Lioness
The Lioness Programming Language
Stars: ✭ 155 (+400%)
Mutual labels:  interpreter, virtual-machine
lunatic
lunatic: a toy lua interpreter
Stars: ✭ 16 (-48.39%)
Mutual labels:  interpreter, virtual-machine
Kivm
🌟This is a pure C++ implementation of Java Virtual Machine (only Java 8 is supported). Inspired by Hotspot In Action.
Stars: ✭ 137 (+341.94%)
Mutual labels:  interpreter, virtual-machine
Swift Lispkit
Interpreter framework for Lisp-based extension and scripting languages on macOS and iOS. LispKit is based on the R7RS standard for Scheme. Its compiler generates bytecode for a virtual machine. LispKit is fully implemented in Swift 5.
Stars: ✭ 228 (+635.48%)
Mutual labels:  interpreter, virtual-machine
Simple
The Simple Intelligent and Modular Programming Language and Environment
Stars: ✭ 120 (+287.1%)
Mutual labels:  interpreter, virtual-machine
clox
A virtual machine and a tree-walk interpreter for the Lox programming language in C89 🌀
Stars: ✭ 38 (+22.58%)
Mutual labels:  interpreter, virtual-machine
Tagha
Minimal, low-level, fast, and self-contained register-based bytecode virtual machine/runtime environment.
Stars: ✭ 79 (+154.84%)
Mutual labels:  interpreter, virtual-machine
Libforth
libforth: A small Forth interpreter that can be used as a library written in c99
Stars: ✭ 107 (+245.16%)
Mutual labels:  interpreter, virtual-machine
wizard-engine
Research WebAssembly Engine
Stars: ✭ 164 (+429.03%)
Mutual labels:  interpreter, virtual-machine
embed
An embeddable, tiny Forth interpreter with metacompiler.
Stars: ✭ 80 (+158.06%)
Mutual labels:  interpreter, virtual-machine

Thislang

thislang logo

About

This-lang (thislang) is an implementation of a subset of Javascript in that subset of Javascript. Yes, it can run itself!

Usage

All output is logged to console. So to use thislang you'll need to open up the console in your browser. Click the Run button to run the code. If you want, you can also explore the outputs from the tokenizer, parser, and compiler.

https://blueblazin.github.io/thislang/

webapp screenshot

thislang running thislang running 'hello world'

Features

  • Data types:
    • Number
    • String
    • Array
    • Object
    • Function
    • Boolean
    • Null
    • Undefined
  • Prototypal Inheritance
  • Function declarations
  • Function expressions
  • Constructors (new calls)
  • Conditionals
  • let variables
  • for and while loops
  • switch statements
  • Single and multi line comments
  • The this context
  • Ability to bind functions
  • Closures
  • Throw statements
  • Try-catch blocks
  • call method on function
  • break and continue
  • spread arguments to function calls (only the last argument)
  • Multiline strings using backticks

Implementation

Thislang is a stack based bytecode Virtual Machine (VM). The interpretation happens in four stages.

  1. Tokenization: the source code is broken down into a stream of lexical tokens.
  2. Parsing: the token stream is parsed into an Abstract Syntax Tree (AST).
  3. Compilation: The AST gets walked and compiled to bytecode.
  4. Execution: The bytecode is executed by the VM.

The file implementation.md details each part of interpreter.

Goals

  • Self-hosting Javascript implementation
  • All features listed above
  • Builtins supporting the most common methods (Object.create, array.map, etc.)

Non-goals

  • Speed
  • Spec-compliance

Implemented builtins

  1. Object.prototype: hasOwnProperty
  2. Array.prototype: push, pop, map, filter, shift, unshift, slice, splice, join
  3. String.prototype: padStart, padEnd, includes
  4. Function.prototype: bind, call
  5. <function>.prototype
  6. <array>.length
  7. <string>.length
  8. console: log, error
  9. Object: getPrototypeOf, is, create, assign, keys
  10. Array: from
  11. print: a debug method that logs the JSObject instead of its string representation.

NOTE: the implementations are roughly similar to their JS equivalents.

Not implemented

  1. Arrow functions
  2. Object and Array destructuring
  3. Class syntax
  4. Template strings
  5. ...and lots more

Bugs

There's no doubt a large number of issues/bugs with the implementation. If you spot any, please open up an issue 😄

Background

For a while after first learning Javascript, I struggled with understanding/remembering how this worked in JS. A couple years ago I thoguht why not rewrite javascript (or rather a subset of it) to get a better understanding of this.

To my own surprise, I actually did it. Of course, you don't need to implement javascript to understand how this works but it was a convenient excuse to convince myself to do it.

Further Improvements

1. Removing dead shapes

The shape system of thislang is a (potentially) massive tree data structure. Whenever an object is created with properties, or a property is added to an object, this tree is walked from its root in order of the property names as they appear on the object.

Thislang will create shapes for all properties and share them whenever it can. However, because the structure holding them is a tree, all shapes are retained in memory. Even those shapes whose originating objects no longer exist.

One way to resolve this issue is to implement a small mark-and-sweep garbage collector that will periodically free up shapes which are no longer pointed to by any object. I might implement this in the future.

2. Better error reporting

The other main improvement is better error reporting. Currently line numbers aren't printed for runtime errors. So recording that alongside bytecode and outputting it is needed. This is a priority and I intend to implement it in the near future.

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].