Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Saffire introduction

Joshua Thijssen
October 07, 2012
270

Saffire introduction

Joshua Thijssen

October 07, 2012
Tweet

Transcript

  1. Saffire
    “programming the web since 2013”

    View Slide

  2. View Slide

  3. Saffire Goals
    • Be a (not the) programming language.
    • Suitable for web (fastCGI) and command
    line.
    • Cool, workable, enjoyable language.

    View Slide

  4. History
    • Decided on learning more about flex / bison.
    • “Why not write a language instead of a
    calculator?”
    • 2 hours later: 2 developers, a github account
    and domains registered.
    • Saffire, dutch/english mix of “saphire” (as in:
    perl / ruby / ...).

    View Slide

  5. History
    • Primarily based on PHP / Python syntax
    with some ideas from other languages
    (java, ruby, javascript).
    • We’re 10-15 years behind, but 10-15 years
    of traps and pitfalls we can avoid.

    View Slide

  6. Technical info
    • Open source (3-clause BSD license).
    • Written in C.
    • Imperative language.
    • Dynamically and strong typed.
    • Byte code generation.
    • Interpreter for now.
    • JIT (and/or compilation) later.

    View Slide

  7. Selling points
    • Everything is an object.
    • Even “foo”, 2, /reg?ex*/ and 3.14159265.
    • UTF-8 out of the box.
    • No functions, just objects and methods.
    • Method and operator overloading.

    View Slide

  8. Hello world
    use io;
    io.print(“hello world”);

    View Slide

  9. Variables and such
    use io;
    $a = 1;
    $b = “foo”.length(); // 3
    $c = “björk”.length(); // 5!
    $d = “björk”.bytes().length(); // 6!
    $e = 1;
    io.print(“$e equals “,$e);

    View Slide

  10. Classes
    use io;
    class Foo {
    const PI = 3.1415;
    protected property $a = 1;
    public method ctor() {
    io.printf(“Constructor called!\n”);
    }
    public method dtor() {
    io.printf(“Destructor called!\n”);
    }
    public method Bar() {
    self.$a++;
    }
    }
    $f = Foo();
    io.printf(“PI is %0.3f“, Foo.PI);
    io.print(“First call: “, $f.bar());
    io.print(“Second call: “, $f.bar());
    $f.destroy(); // $f is no more

    View Slide

  11. Modules
    use io;
    use FooFramework as Foo;
    use BarFramework;
    $foo = Foo::Framework();
    $content = $foo->run();
    $req = BarFramework::HTTP::Request();
    $req.status = 200;
    $req.content = $content;
    $req.out();

    View Slide

  12. Operator Overloading
    use io;
    class Foo {
    protected property $a;
    public method ctor(String $a) {
    self.$a = $a;
    }
    public method ::+(String $b) {
    return self.$a.concat(“ “, $b);
    }
    }
    $f = Foo(“hello”);
    $f += “world”;
    io.printf($f, “\n”);

    View Slide

  13. Method Overloading
    class Foo {
    public method foo(String $a) {
    // Do something with a string
    }
    public method foo(Numerical $a) {
    // Do something with a numerical
    }
    public method foo($a) {
    // Any object (not string or numerical)
    }
    }

    View Slide

  14. Saffire for PHP
    • FastCGI and CLI only
    • “compiled” bytecode (*.sfc files)
    • UTF-8 - strlen(), strpos() etc.
    • Objects, objects everywhere
    • Method and operator overloading
    • There are no arrays (hashmaps & lists)
    • Multi assignments: $a, $b = 1, 2;
    • Empty assignments: $a, ,$b = 1, 2, 3;

    View Slide

  15. Saffire for PHP
    • By default returns “self” ($this)
    (fluent interface)
    • foreach/else while/else breakelse
    • try / catch / finally
    • “ducktyping” and interfacing are supported
    • Out of the box annotation-reader

    View Slide

  16. Saffire for PHP
    2.add(3); // return Numerical(5)
    “foo”.reverse(); // returns String(“oof”)

    View Slide

  17. Current Status
    • Initial scanning / parsing done (flex/bison).
    Might change to lemon.
    • Language specification on its way.
    • Still figuring out problems.
    • Abstract Syntax Trees (AST) can be
    generated.
    • Initial object module engine created (heavily
    based on Python’s)
    • Initial bytecode generator

    View Slide

  18. $./saffire test.sf --dot test.dot

    View Slide

  19. View Slide

  20. What’s next
    A)Get “something” running fast, but poor.
    B) Do things properly but takes (much) more
    time.
    C)All of the above...

    View Slide

  21. What’s next
    • Finish the language specification.
    • Implementation specification
    • Bytecode optimization phase (?)
    • Create the interpreter.
    • Create a more stable lex / parse system
    (pureparser / lemon)
    • ???
    • Profit

    View Slide

  22. (Un)Stable release?
    • Depends on the help!
    • 0.01 not until somewhere (late) 2013.
    • Roadmap hasn’t been created.
    • First (dutch) meetup: 26 october 2012

    View Slide

  23. We need YOU...
    • C programmers, but many, many others for
    websites, documentation, language
    specification, testing/QA, app writers,
    framework writers, evangelists, etc, etc..
    • USERBASE!
    • If you can read this, you can help us!

    View Slide

  24. Find us!
    • IRC: freenode.org #saffire
    • mailinglist: https://groups.google.com/group/
    saffire-internals
    • website: http://saffire-lang.org
    • github: https://github.com/saffire/saffire
    • twitter: @saffire-lang

    View Slide

  25. io.print(“Thank you!”);

    View Slide