• Stars
    star
    182
  • Rank 204,310 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A script language for .Net and the CLR

Lizzie a scripting language for .Net

Build status

Lizzie is a dynamic scripting language for .Net based upon a design pattern called "Symbolic Delegates". This allows you to execute dynamically created scripts, that does neither compile nor are interpreted, but instead "compiles" directly down to managed CLR delegates. Below is an example of using Lizzie from C#.

using System;
using lizzie;

class MainClass
{
    public static void Main(string[] args)
    {
        // Some inline Lizzie code
        var code = @"

// Multiples 10 by 2 and adds to 57
+(57, *(10, 2))

";

        // Creating a Lizzie lambda object from the above code, and evaluating it
        var lambda = LambdaCompiler.Compile(code);
        var result = lambda();

        // Writing the result of the above evaluation to the console
        Console.WriteLine("Result was: " + result);

        // Waiting for user input
        Console.Read();
    }
}

Lizzie is highly influenced and inspired from Lisp, but without the unintuitive "Polish notation". In such a way, it arguably is dynamic Lisp for the CLR. Its dynamic nature allows you to execute snippets of Lizzie code, inline in your C# code, by loading your code from files, or by for instance fetching the code from some database of some sort, or even transmit code over the network to have a server endpoint (securely) evaluate your code.

You can easily create your own "keywords" in Lizzie, which allows you to create your own DSL or "Domain Specific programming Languages". Lizzie hence easily lends itself to richer rule based engines, and similar domain specific problems, where your code needs to be more dynamic in nature than that which the CLR allows you to through C#, VB.NET or F#.

What is a Symbolic Delegate?

A Symbolic Delegate is a CLR delegate that is dynamically looked up during runtime from a dictionary of delegates with the same signature. This allows you to dynamically wire together delegates to an "execution tree" during runtime, based upon whatever delegate happens to be the value for your "symbol". Lizzie is literally a dictionary of delegates, where the key to lookup your delegates are of type string. This allows you to easily extend Lizzie by simply creating a new delegate, and associating it with a "symbol", to such have access to execute CLR methods from your Lizzie script code.

MSDN Article about symbolic delegates written by yours truly

Binding Lizzie to your own types

If you want to, you can "bind" your Lizzie code to a CLR type. This allows you to extend your Lizzie code with your own C# "keywords", to create your own "DSL". Below is an example.

using System;
using lizzie;

class MainClass
{
    [Bind(Name = "write")]
    object Write(Binder<MainClass> ctx, Arguments arguments)
    {
        Console.WriteLine(arguments.Get<string>(0));
        return null;
    }

    public static void Main(string[] args)
    {
        // Some inline Lizzie code
        var code = @"

write('Hello World!!')

";

        // Creating a lambda function from our code, and evaluating it
        var function = LambdaCompiler.Compile(new MainClass(), code);
        function();
    }
}

How small is Lizzie?

The entire reference documentation for Lizze is roughly 12 pages if you choose to print it. This is the entire reference documentation for the language. This allows you to learn the entire programming language literally in 20 minutes. The "compiler" for the language is less than 500 lines of code, and all "keywords" are less than 1,000 lines of code in total. The project as a whole has roughly 2,200 lines of code, but 50% of these are comments. When built, the DLL is roughly 45KB on disc. There are 7 public classes in the project, one attribute, and one interface. There are less than 30 methods in total, and you don't have to use more than a handful of these to start adding dynamic scripting abilities to your CLR code. This arguably makes Lizzie the smallest (useful) programming language on the planet, if you ignore languages such as "brainfuck", arguably created more or less as a joke.

The Lizzie tokenizer also contains only 7 different tokens. There are no operators in the language, no keywords, and only one type of statement. In fact all "statements" are "functions", that all have the same signature. Compare this to the 500+ keywords, and 50+ operators of C#, and the 1,000+ pages of reference documentation for C#, and hopefully you understand the advantage.

How fast is Lizzie

When profiling a language such as Lizzie, there are two important things to measure.

  • Compilation speed
  • Execution speed

Compilation is blistering fast, at least if you consider the fact that the compiler is written in C#. Below is an example that compiles 10,000 snippets of Lizzie code. On my machine this code is finished after ~2 seconds.

using System;
using System.Diagnostics;
using lizzie;

class MainClass
{
    public static void Main(string[] args)
    {
        // Some inline Lizzie code
        var code = @"
+(5, 2, 50)
-(100, 30, 3)
*(5, 3, 2)
/(100, 4)
%(18, 4)
";

        // Compiling the above code 10,000 times
        Console.WriteLine("Compiling some Lizzie code 10,000 times, please wait ...");
        Stopwatch sw = Stopwatch.StartNew();
        for (var idx = 0; idx < 10000; idx++) {
            var lambda = LambdaCompiler.Compile(code);
        }
        sw.Stop();
        Console.WriteLine($"We compiled the above code 10,000x in {sw.ElapsedMilliseconds} milliseconds");

        // Waiting for user input
        Console.Read();
    }
}

On my computer, which is a MacBook Air from 2016, the above code compiles 10,000 times in roughly 2,100 milliseconds. Since Lizzie is a dynamic scripting language, intended to frequently retrieve snippets of dynamic code, and compile these, before it executes the result - The compilation speed is hence arguably equally important as its execution speed. On my computer, compiling Lizzie itself, and its unit tests once requires 4.62 seconds! Compiling the above Lizzie code 10,000 times took me only 2 seconds.

Execution speed

If we slightly modify our above code, to execute the code 10,000 times, instead of compiling it 10,000 times, such that it resembles the following ...

using System;
using System.Diagnostics;
using lizzie;

class MainClass
{
    public static void Main(string[] args)
    {
        // Some inline Lizzie code.
        var code = @"
+(5, 2, 50)
-(100, 30, 3)
*(5, 3, 2)
/(100, 4)
%(18, 4)
";

        // Executing the above code 10,000 times!
        Console.WriteLine("Executing some Lizzie code 10,000 times, please wait ...");
        var lambda = LambdaCompiler.Compile(code);
        Stopwatch sw = Stopwatch.StartNew();
        for (var idx = 0; idx < 10000; idx++) {
            lambda();
        }
        sw.Stop();
        Console.WriteLine($"We executed the above code 10,000x in {sw.ElapsedMilliseconds} milliseconds!");

        // Waiting for user input.
        Console.Read();
    }
}

The results on my computer says 722 milliseconds.

Lizzie is not as fast as C#, since each function invocation also requires a lookup into a Dictionary. Each function invocation also implies evaluating a delegate, which has an additional overhead of 20% compared to invoking a virtual method. So you can't expect a Lizzie lambda object to evaluate nearly as fast as the equivalent C# method. However, compared to the execution speed of an interpreter written on the CLR, and/or a "true compiler" written on the CLR, Lizzie will purely mathematically outperform both of these for all practical concerns, assuming you have an interest in executing dynamic code. Since most practical snippets of code does complex tasks, such as accessing the file system, and reading/writing to databases, fetching data over sockets, etc - The execution speed overhead of your Lizzie code for most practical concerns will be irrelevant.

DISCLAIMER - I would not encourage you to use Lizzie for extremely CPU resource demanding tasks, such as polygon rendering, algorithmic intensive math operations, complex parsing, etc. Because after all, it will never execute as fast as the equivalent C# code, due to its dynamic nature.

A 5 minutes introductory video to Lizzie

A 5 minutes introduction video to Lizzie

Reference documentation

Installation

PM > Install-Package lizzie

Or visit the download page to get its source code

More Repositories

1

magic

An AI-based Low-Code and No-Code software development automation framework
TypeScript
959
star
2

phosphorusfive

A Full Stack RAD Web Application Development Framework
C#
178
star
3

hyper-ide

Hyper IDE - A web based IDE for 100+ programming languages
JavaScript
54
star
4

sephia-five

A secure and PGP enabled webmail module for Phosphorus Five
CSS
26
star
5

phosphorusfive-dox

Phosphorus Five, the Guide
13
star
6

magic.io

Generic upload download file controller for ASP.NET Core
C#
10
star
7

magic.http

An opinionated HTTP REST library for .Net
C#
7
star
8

schwoogle

Because Google Sux!
HTML
7
star
9

cronos

Algebraic DateRange operations
C#
7
star
10

magic.lambda.crypto

Crypto plugin for magic.lambda
C#
6
star
11

anarq

An Open Source alternative to Facebook, Reddit and Disqus
HTML
6
star
12

magic.lambda.hyperlambda

Hyperlambda plugin for magic.lambda
C#
6
star
13

magic.node

A generic graph object for the CLR
C#
5
star
14

magic.lambda

A Turing complete microscopic DSL built on top of Magic Signals
C#
5
star
15

system42

An anti-CMS, this module is deprecated
JavaScript
5
star
16

rosetta

Rosetta is a small and blistering fast, ultra secure web server, aiming at turning everything with a network card, into a potential web server. It supports SSL, thread pooling, persistent connections, pipelining, max-connections per client, If-Modified-Since, and much more.
C++
5
star
17

magix

Magix Illuminate Phosphorus
C#
4
star
18

camphora-five

A CRUD app generator that doesn't require coding skills
CSS
4
star
19

tickets

Aista's ticketing system
HTML
4
star
20

magic.publishing

Magic Publishing, a super fast .Net Core based CMS
TypeScript
4
star
21

micro

A microscopic CSS framework
JavaScript
4
star
22

polterguy.github.io

GitHub pages for Magic
HTML
4
star
23

magic.crypto

Simplified cryptography functions for C#
C#
4
star
24

magic.lambda.mssql

SQL Server plugin for magic.lambda
C#
4
star
25

sulphur-five

A secure file sharing module for Phosphorus Five
CSS
3
star
26

magic.lambda.math

Math plugin for magic.lambda
C#
3
star
27

magic.deploy

Helper deploy repository for Magic
3
star
28

magic.lambda.strings

String manipulation plugin for Magic
C#
3
star
29

magic.lambda.auth

Auth plugin for magic.lambda
C#
3
star
30

Babelizer

Localisation application for your enterprise needs
TypeScript
2
star
31

magic.lambda.dates

Date helper slots for Magic
C#
2
star
32

magic.clone

Shell
2
star
33

sakila

An Angular/.Net Core Web app wrapping MySQL's Sakila database
TypeScript
2
star
34

hypereval

Hyperlambda snippets modules for Phosphorus Five
2
star
35

magic.endpoint

A dynamic Hyperlambda endpoint evaluator for Magic
C#
2
star
36

magic.lambda.json

JSON plugin for magic.lambda
C#
2
star
37

magic.lambda.validators

C#
2
star
38

magic.lambda.http

HTTP REST invocation plugin for magic.lambda
C#
2
star
39

magic.signals

A dynamic function invocation library for .Net Core
C#
2
star
40

magic.lambda.logging

Logging plugin for magic.lambda
C#
2
star
41

magic.lambda.sqlite

SQLite data adapters for Magic
C#
2
star
42

magic.lambda.mime

The ability to parse and create MIME messages from Hyperlambda
C#
2
star
43

magic.lambda.mysql

MySQL data adapters for magic
C#
2
star
44

magic.lambda.config

Configuration slots for magic.lambda
C#
2
star
45

magic.lambda.caching

Implements caching slots for Magic
C#
2
star
46

magic.data.common

Commonalities for MS SQL and MySQL Magic data adapters
C#
2
star
47

magic.lambda.scheduler

A scheduler for Magic
C#
2
star
48

magic.lambda.image

An image manipulation component for Magic
C#
2
star
49

magic-menu

An alternative input module for Phosphorus Five, allowing you to use natural language and speech recognition to control your apps
CSS
2
star
50

stripe

Payment helper Hyperlambda library
2
star
51

gpt-commerce

2
star
52

magic.lambda.threading

Threading plugin for Hyperlambda and Magic
C#
1
star
53

magic.lambda.io

IO plugin for magic.lambda
C#
1
star
54

license

License module for Phosphorus Five
1
star
55

magic.library

Helper project to wire up Magic
C#
1
star
56

magic.lambda.html

HTML parsing for Magic and Hyperlambda
C#
1
star
57

sqlite-northwind

Northwind database script for SQLite
1
star
58

magic.lambda.system

System slots for Magic to allow for creating terminal processes, etc
C#
1
star
59

peeples

The user management module for Phosphorus Five
CSS
1
star
60

magic.lambda.csv

CSV parsing capabilities for Magic
C#
1
star
61

robo-crm.frontend

TypeScript
1
star
62

mssql-northwind

SQL Server Northwind database
TSQL
1
star
63

expert-ai

AI expert system
TypeScript
1
star
64

babelfish

Translation service for your own apps
TSQL
1
star
65

magic.lambda.slots

Dynamic slot creation in Magic
C#
1
star
66

ingen

A Dinosaur Theme Park Software System illustrating usage of Phosphorus Five
CSS
1
star
67

Tamagotchi

A microscopic Tamagotchi implementation
C#
1
star
68

aista-jekyll

A Content First Jekyll Theme
CSS
1
star
69

anarq.frontend

Frontend parts for Anarchy
TypeScript
1
star
70

hyperbuild

Build system for Phosphorus Five, and its associated plugins
1
star
71

Aista.Data.Sqlite

Port of Microsoft.Data.Sqlite
C#
1
star
72

babelfish.frontend

TypeScript
1
star
73

phosphorus-unit-tests

Unit tests for Phosphorus Five
1
star
74

ra-ajax

Automatically exported from code.google.com/p/ra-ajax
C#
1
star
75

magic.lambda.mail

SMTP and POP3 helpers for Magic
C#
1
star
76

hyper-core

A MySQL HTTP REST based ORM - And more
1
star
77

hyper-sql

A web based alternative to MySQL workbench
CSS
1
star
78

magic.lambda.sockets

Web sockets connection support for Magic
C#
1
star
79

aista.harvester

A wait for release type of Angular SPA, allowing users to subscribe to newsletter
TypeScript
1
star
80

notifications

Notifications service for Magic
1
star
81

magic.data.cql

ScyllaDB data adapters for files and such in Magic
C#
1
star
82

registration

Hyperlambda registration module for Magic
1
star