Skip to content

built1n/ducky

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ducky

IRC: #ducky-lang at irc.freenode.net

Introduction

Ducky is a BASIC-like programming language originally insipred by Duckyscript, the USB Rubber Ducky's scripting language.

Examples

Hello World

#!/bin/ducky
LOG Hello, world!
NEWLINE

Simple!

Fibonacci Sequence

#!/bin/ducky
LET a = 0; LET b = 0; LET iter = 0
LABEL loop_start
LOGVAR a
NEWLINE
LET c = a+b
LET a = b
LET b = c
INC iter
IF iter < 20; GOTO loop_start
LOG Done!
NEWLINE

Prime Counter

#!/bin/ducky
LOG Counting...
NEWLINE
LET primes=0
LET MAX=100000
LET n = 2
LBL test_number
LET iter = 2
LET stop = sqrt n
LBL test_loop
IF !(n % iter); GOTO composite
INC iter
IF iter <= stop; GOTO test_loop
INC primes
LBL composite
INC n
IF n < MAX; GOTO test_number
LOG Number of primes below
LOGVAR MAX
LOG :
LOGVAR primes
NEWLINE

Building

POSIX systems are supported, as are some Rockbox targets.

Unix/Linux

make
sudo make install

This installs the /bin/ducky binary.

Usage

Running Directly (no compilation)

ducky scriptname.ds

Compiling to bytecode

ducky -c scriptname.ds

This will create a.out, which contains the bytecode.

Executing bytecode

ducky a.out

Full Compile (from ducky to machine code)

ducky -a scriptname.ds
./a.out

Technical Details

The program consists of four parts: the interpreter, compiler, bytecode interpreter, and C transcompiler.

Interpreter

Executes ducky directly.

Bytecode Compiler

Compiles ducky to a stack-machine based bytecode.

Bytecode Interpreter

Executes the bytecode generated by the bytecode compiler.

C Transcompiler

Translates bytecode generated by the bytecode compiler into C.

Benchmark Results

21 Nov 2015:

c - clang     26 27 27 27 27 27 27 27 27 27 - AVG 26.9
c - gcc       29 29 29 29 29 29 29 29 29 29 - AVG 29
c - tcc       28 28 28 28 28 28 28 28 28 28 - AVG 28
ducky - clang 15 15 15 15 15 15 15 15 15 15 - AVG 15
ducky - gcc   28 28 28 28 28 28 28 28 28 26 - AVG 27.8

26 Nov 2015:

LanguageCompilerOptimization LevelScoresMean score
DuckyClang-O04 4 4 4 4 4 4 4 4 4 4
DuckyClang-O115 15 15 15 15 15 15 15 15 1515
DuckyClang-O221 21 21 21 21 21 21 21 21 2121
DuckyClang-O321 21 21 21 21 21 21 21 21 2121
DuckyGCC-O05 5 4 5 5 5 5 5 5 5 4.9
DuckyGCC-O122 23 23 23 23 23 23 23 23 2322.9
DuckyGCC-O226 26 26 26 26 26 26 26 26 2626
DuckyGCC-O326 26 26 26 26 26 26 26 26 2626
CClang-O028 28 28 28 28 28 28 28 28 2828
CClang-O128 29 29 28 28 28 28 28 29 2928.4
CClang-O228 29 29 29 28 29 29 28 28 2828.4
CClang-O328 28 28 29 28 29 28 29 28 2828.3
CGCC-O028 28 28 28 28 28 28 28 28 2828
CGCC-O130 30 30 30 29 30 29 30 30 2929.7
CGCC-O230 30 30 30 30 30 30 30 30 3030
CGCC-O330 30 30 30 30 30 30 30 30 3030

Future Directions

  • Refactor code
  • Input
  • Add more builtins
  • Arrays?
  • Functions?

About

A simple BASIC-like programming language compiling into C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages