Skip to content

yjlo123/runtime-script

Repository files navigation

Runtime Script

An assembly-like programming language.

def hello
 let _names $0
 #loop
 pol $_names _name
 jeq $_name $nil done
 add _msg 'Hello ' $_name
 prt $_msg
 jmp loop
 #done
 ret
end

let names []
psh $names 'World' 'yjlo'
cal hello $names

Playground

https://runtime.siwei.dev

Run using Node.js

node run.js <runtime_file>

Tutorial

https://siwei.dev/doc/runtime

Examples

Game: Snake
Game: Flappy Bird
Game: Sliding Puzzle
Game: Sokoban
Game: 2048

Leetcode 1. Two Sum
Leetcode 5. Longest Palindromic Substring
Leetcode 20. Valid Parentheses
Leetcode 21. Merge Two Sorted Lists
Leetcode 122. Best Time to Buy and Sell Stock II
Leetcode 136. Single Number
Leetcode 231. Power of Two
Leetcode 344. Reverse String
Leetcode 412. Fizz Buzz

Digital Clock
Selection Sort

Brainfuck Interpreter
Runtime Script Interpreter

Games written in Runtime Script

倉庫番: A sokoban game
2048: A 2048 game
Rundis: A mock Redis CLI
MoonOS: A terminal game
Wordle: A word game

Editor

Online Editor
Visual Studio Code Extension

Blog

#runtime_script

Other implementations

Runtime Go
Runtime Python

Language reference

let N V
prt V V*

# data type
int N V
str N V
typ N V

# arithmetic
add N V V
sub N V V
mul N V V
div N V V
mod N V V

# jump
jmp L
jeq V V L
jne V V L
jlt V V L
jgt V V L

# data structure
psh S V [V..]
pop S N
pol S N
put S I V
get S I N

put M V V
get M V N
key M N
del M V

len S/M N

# canvas
clr V*
drw V V V
pxl N V V

# misc
inp N
slp V
rnd N V V
tim N year|month|date|day|hour|minute|second|milli|now
prs N V
lod V N
sav V V

# if-else
ife V V
ifg V V
els
fin

# for-loop
for N V
nxt

# function
def F
ret V*
end
cal F
N: variable name
V: variable reference ($VR)
   or value (int|str|[]|{})
S: list|str $VR
M: map $VR
I: int or int $VR
L: label
F: function name