GithubHelp home page GithubHelp logo

built1n / ducky Goto Github PK

View Code? Open in Web Editor NEW
10.0 5.0 1.0 112 KB

A simple BASIC-like programming language compiling into C

License: GNU General Public License v2.0

Makefile 0.42% C 98.84% Assembly 0.67% Shell 0.07%

ducky's Introduction

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?

ducky's People

Contributors

built1n avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

foolsh

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.