Giter VIP home page Giter VIP logo

foolang's Introduction

Foolang

CI License: MIT

This is a toy language implemented by a single person—use for quiet enjoyment only.

See https://foolang.org for syntax, design notes, etc. This README is a smaller version of the main page there.

See CONTRIBUTING.md for information on how to contribute. You'll be the first. :)

About

Foolang is a Smalltalk-inspired language that, like all new languages, has somewhat optimistic aspirations:

  • Elegance and power of Smalltalk and Self: Smalltalk/Objective-C -like syntax, deep object orientation, late binding, interactive development.

  • Performance of C++: AOT compilation to native code, support for early binding so that the compiler can do its thing, low-level datatypes and operations when you need them for performance.

  • Fault tolerance of Erlang: Actor-model, isolated heaps, and supervisors. No undefined behaviour. No deadlocks, or memory errors or races.

  • Multiplatform Citizen of the Web: WASM is a supported target in addition to Windows, MacOS, Linux, and BSDs.

"Are we there yet?"

🤣

Syntax is still going to change, WASM isn't supported, BSDs might work but aren't tested, early binding support isn't quite there, compiler is a work-in-progress trivial transpiler, actors and continuations haven't even been started, there is no interactive development environment to speak of, etc.

Hello World

class Main {}
    direct method run: command in: system
        system output println: "Hello world"!
end

Repository Organization

In rough order of interest:

foo/       Foolang code, including prelude, self hosting, tests, and examples
src/       Rust code for the bootstrap interpreter
docs/      Markdown files for the https://foolang.org website
elisp/     Emacs mode for Foolang
c/         Scaffolding for transpiled-to-C code
tests/     Rust code for integration tests
ext/       External C code included in the runtime, like dtoa.c.

foolang's People

Contributors

nikodemus 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

Watchers

 avatar  avatar  avatar  avatar  avatar

foolang's Issues

Empty array constructor broken

$ ./target/debug/foolang --eval "[]"
thread 'main' panicked at 'Could not parse expression: []
Error: Unrecognized token `]` found at 1:2

foolang.el: indentation hangs

class Main {}
    class method run: cmd in: sys
        let c = C new.
        sys output println: "foo: {self foo: c} => I0 ok?".
        sys output println: "bar: {self bar: c} => I1 ok?".
        sys output println: "quux: {self quux: c} => I ok?"<ENTER>
end

Hitting where marked leaves emacs spinning until C-g.

class invariants

To be checked on initialization and method exit.

syntax sketch:

class Foo { a b }
    invariant: a < b
    ...
end

#selector syntax

Creating literal selector objects.

Methods:

  • Block interface: #selector value: x --> x selector, allowing
    foo do: { |x| x selector } --> foo do: #selector
    
  • #sendTo:, #sendTo:with:

Implicit _ argument in blocks

Ie.

{ |x| foo x: x } == { foo x: _ }

(This is one of the more ambitious "good first issues" -- I would suggest doing this in self-hosted implementation only at first. My own plan is to postpone this until self-hosting is complete, but it can be done sooner.)

File class

  • design
  • Filepath#file -> File
  • File#forRead specifies readmode
  • File#forWrite specifies writemode
  • File#forAppend specifies appendmode
  • File#truncateExisting specifies that existing file should be truncated
  • File#open -> FileStream, requires file to exist
  • File#create -> FileStream, requires file not to exist.
  • File#createOrOpen -> FileStream, if file does not exist creates it

An exception is raised if no modes have been specified before open/create/createOrOpen.

Closure#apply

It should be possible to apply arrays to blocks:

{ |x y| x + y } apply: [40, 2] --> 42

Character class

Class representing Unicode codepoints / scalar values.

Methods should provide facilities similar to rust's char.

String should gain related methods as well.

Critically needed:

  • isDigit
  • isWhitespace
  • digit

script error exits with 0, not 1

nikod@LAPTOP-BLUHQ6AB MINGW64 ~/src/foolang (master)
$ cat bad.foo
this is broken


nikod@LAPTOP-BLUHQ6AB MINGW64 ~/src/foolang (master)
$ cargo run --bin foolang -- bad.foo 2> /dev/null && echo OK
ERROR: Undefined class

OK

foo[x] as sugar for foo at: x

Alternatively I could take the Ruby route and allow methods like this:

method [key]
   ...

method [key] = value
   ...

The same approch would speak to my question, "what about function call syntax?":

method (x)
   ...
method (x,y)
   ...

Arrays generator for Assert

Depends on #98 being implemented first.

Usage something like:

assert forAll: (Arrays of: Integers) ...
  • Have a look how Hypothesis generates its more complex objects.
  • Figure out how to drive the lower-level generator.
  • Implement it.

association syntax: key -> value

key -> value --> Association from: key to: value

Implement as operator or syntax?

Pro syntax:

  • Cannot be overridden
  • { a -> x } is a dictionary
  • -> is already syntax in method signatures
  • Support for destructuring possible: dict do: { |a -> b| ... }

Pro operator:

  • less syntax, less special casing
  • {} syntax is already wrought

Current thinking: syntax. Mainly because -> is already syntax instead of an operator.

But why is association syntax needed in the first place? ...that's a really good question. Maybe it's not needed right now after all.

let x = 42 at toplevel creates a global definition

Should require a define. (Fallout from environment refactoring.)

foo/toplevel_let.foo:

let X = 123

Then:

$ cargo run -- foo/repl.foo --use foo
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
     Running `target\debug\foolang.exe foo/repl.foo --use foo`
Foolang 0.2.0
> import foo.toplevel_let.X
"foo\toplevel_let.foo"
> X
123

Options:

  • Pretend that's the way it's supposed to work.
  • Make it not do that, and instead implement define.

Inheritable interfaces with default and required methods

Branch: interfaces

  • define interface syntax
  • define inheritance syntax
  • parse into InterfaceDefinition with default methods
  • parse required methods as well
  • parse is in class as inheriting an interface
  • eval_interfaces creates a vtable
  • eval_class initializes the class vtable from inherited interfaces and reports conflicts
  • handle required but unimplemented methods in eval_interface and eval_class
  • make_class and make_interface ensure that overridden and defined methods have signatures that match interfaces
  • typechecking understands interfaces
  • extend allows adding interfaces to classes
  • allow interfaces to inherit each other

FilePath class

  • minimal design sketch & docs
  • implementation
  • tests

Question!

System files is not the same as current working directory. ...but we do need access to current working directory. Should there be System#currentDirectory that just returns the string? Or is that a FilePath too?

Test case saving for Assert

Depends on #52, #53, and #54. (Filesystem stuff.)

Hypothesis uses a database, need to think about this. OTOH, an SQLite interface would be a good thing to have anyhow...

FileStream class

  • close
  • flush
  • isClosed
  • isOpen
  • size
  • resize: size
  • offset
  • offset: absolute
  • offsetFromEnd: relative
  • offsetFromHere: relative
  • readBytes
  • readString
  • read: n bytesInto: byteArray at: index
  • write: n bytesFrom: byteArray at: index
  • tryRead: n bytesInto: byteArray at: index
  • tryWrite: n bytesFrom: byteArray at: index
  • tryReadOnce: n bytesInto: byteArray at: index
  • tryWriteOnce: n bytesFrom: byteArray at: index
  • writeBytes: bytes
  • writeString: string

Decide on notation for class vs instance methods in prose and docs

Some options:

  • Class method vs Class#method (space vs #)
    Probably: requires quoting in text as in: "Using List defaultCapacity one can..." vs "Using List defaultCapacity one can..."
  • Class#classmethod vs class#instancemethod (casing)
    PROBABLY NO: doesn't work with lowercase classes, which I'm more inclined to allow now.
  • Class##classmethod vs Class#method (# vs ##)
    MAYBE: not super intuitive -- could be the other way around as well
  • Class>method vs Class>>method
  • Class class>>method vs Class>>method

Decision for now: Class method and Class#method.

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.