GithubHelp home page GithubHelp logo

lone-lang / lone Goto Github PK

View Code? Open in Web Editor NEW
298.0 10.0 8.0 866 KB

The standalone Linux Lisp

License: GNU Affero General Public License v3.0

Makefile 2.07% C 93.27% GDB 1.87% Shell 2.78%
freestanding freestanding-application freestanding-environments linux linux-shell lisp lisp-interpreter standalone standalone-executables programming-language

lone's People

Contributors

danielsz avatar matheusmoreira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lone's Issues

A type-safe representation of tagged unions

Hi there! I came from your Reddit post and found this project fascinating.

While reading the sources, I've found the header include/lone/types.h, which uses a common technique of tagged unions. Most notably, struct lone_value:

struct lone_value {
	// Auxiliary data...

	enum lone_type type;

	union {
		struct lone_module module;
		struct lone_function function;
		struct lone_primitive primitive;
		struct lone_list list;
		struct lone_vector vector;
		struct lone_table table;
		struct lone_bytes bytes;
		struct lone_pointer pointer;
		long integer;
	};
};

The downside of this approach is that it's possible to mess up during case analysis by 1) not checking a tag, or by 2) checking a tag A and then using B. The compiler cannot check this automatically, causing the bug to silently creep into the final executable.

Instead of managing tagged unions manually, I would suggest using Datatype99, which is a header-only library designed specifically to deal with the problem of tagged unions. struct lone_value would look as follows 1:

datatype(
    LoneValue,
    (LoneModule, struct lone_module),
    (LoneFunction, struct lone_function),
    (LonePrimitive, struct lone_primitive),
    (LoneList, struct lone_list),
    (LoneVector, struct lone_vector),
    (LoneTable, struct lone_table),
    (LoneBytes, struct lone_bytes),
    (LonePointer, struct lone_pointer),
    (LoneInteger, long)
);

And case-analyzed as follows:

void handle(LoneValue value) {
    match(value) {
        of(LoneModule, module) { /* ... */ }
        of(LoneFunction, function) { /* ... */ }
        of(LonePrimitive, primitive) { /* ... */ }
        of(LoneList, list) { /* ... */ }
        of(LoneVector, vector) { /* ... */ }
        of(LoneTable, table) { /* ... */ }
        of(LoneBytes, bytes) { /* ... */ }
        of(LonePointer, pointer) { /* ... */ }
        of(LoneInteger, integer) { /* ... */ }
    }
}

Since of explicitly provides a variable binding, such as module or function, it's now much harder to make a mistake. The datatype encoding is also more concise than the corresponding tagged union representation, since the former defines both enum lone_type and struct lone_value 2.

Since Datatype99 has no run-time dependencies (not even the C standard library), and has a transparent and formally specified semantics, I think it might be a great fit for Lone 3.

Let me know if you have any thoughts or questions, which I should be able to answer.

Footnotes

  1. Auxiliary data can be added as a separate structure.

  2. Although both types can be manipulated separately under the names LoneValueTag and LoneValue.

  3. Other tagged unions in the project can be rewritten in the same way, if there are any.

Graphics - to add to the list of features?

I appreciate it may not be done yet, but the ability to make fat UI applications (or not) would be a great addition to the list.

Context: QML is interesting, but I think they missed an opportunity - https://paulhammant.com/2016/11/15/qmls-squandered-opportunity/. In that post I talk of a calculator and there are loads of attempts at making it as a demo in different techs. The web has many, and one or two are "single file" for that. Of course Lisp is the grandpappy language for elegant pseudo-declarative apps - https://paulhammant.com/2013/03/28/interface-builders-alternative-lisp-timeline so I'd imagine it was possible and terse/elegant. That's racing ahead as lone-lang should note whether it can do UI or not :)

Great work though!

Stack smashing protection

GCC stack smashing protection references:

When stack smashing protection is turned on, the compiler generates some fairly simple code:

extern uintptr_t __stack_chk_guard;
noreturn void __stack_chk_fail(void);

void foo(const char* str)
{
	uintptr_t canary = __stack_chk_guard;

	/* ... */

	if ( (canary = canary ^ __stack_chk_guard) != 0 )
		__stack_chk_fail();
}

It looks like all we have to do is initialize __stack_chk_guard to a random number and provide a __stack_chk_fail function which exits the program. Linux provides 16 random bytes to every process via the auxiliary vector and lone already uses those to initialize its hash functions. It should be possible to use those random bytes to initialize the stack canary as well.

Originally posted by @matheusmoreira in #3 (comment)

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.