Code Monkey home page Code Monkey logo

fe-d's Introduction

fe

A tiny, embeddable language implemented in ANSI C D.

Note: this is a fork, with the implementation translated to D. See original repo here: https://github.com/rxi/fe

(= reverse (fn (lst)
  (let res nil)
  (while lst
    (= res (cons (car lst) res))
    (= lst (cdr lst))
  )
  res
))

(= animals '("cat" "dog" "fox"))

(print (reverse animals)) ; => ("fox" "dog" "cat")

Overview

  • Supports numbers, symbols, strings, pairs, lambdas, macros
  • Lexically scoped variables, closures
  • Small memory usage within a fixed-sized memory region — no mallocs
  • Simple mark and sweep garbage collector
  • Easy to use C API
  • Portable ANSI C — works on 32 and 64bit
  • Concise — less than 800 sloc

Contributing

The library focuses on being lightweight and minimal; pull requests will likely not be merged. Bug reports and questions are welcome.

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

Full D interpreter

import std.stdio;
import std.file;
import fe;
import core.stdc.stdlib;

int main(string[] args)
{
    if (args.length != 2)
    {
        writeln("Usage: fe-interp <source.fe>");
        return 1;
    }

    int size = 1024 * 1024;
    void* data = malloc(size);

    fe_Context* ctx = fe_open(data, size);
    const(char)[] source = cast(char[]) std.file.read(args[1]);

    struct UserContext
    {
        const(char)[] remain;
    }

    static char readInBuf(fe_Context *ctx, void* udata)
    {
        UserContext* uc = cast(UserContext*)udata;
        if (uc.remain.length == 0)
            return '\0';
        else
        {
            char c = uc.remain[0];
            uc.remain = uc.remain[1..$];
            return c;
        }
    }

    int gc = fe_savegc(ctx);
    UserContext uc;
    uc.remain = source;
    while(true)
    {
        fe_Object *obj = fe_read(ctx, &readInBuf, &uc);

        // break if there's nothing left to read
        if (!obj) break;

        // evaluate read object
        fe_eval(ctx, obj);
    }
    // restore GC stack which would now contain 
    // both the read object and result from evaluation
    fe_restoregc(ctx, gc);

    fe_close(ctx);
    return 0;
}

fe-d's People

Contributors

p0nce avatar

Stargazers

Brad Svercl avatar

Watchers

 avatar

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.