Coder Social home page Coder Social logo

tiro's Issues

Implement basic functionality in standard library

  • to_string() for builtin object types
    Builtin types (containers, result, etc.) should have useful string representations for printing/debugging
  • Basic math functions (round, floor, ceil, trigonometry, ...) and constants (pi, e)
  • String utilities
    • find/replace/etc
    • maybe even some unicode support? The runtime should enforce utf8

Support max heap size setting

Expose max heap size setting during vm construction.
The heap already supports this internally, it needs to be exposed in the API and tested as well.

Eager module initialization on application startup

The current implementation of module loading is lazy, i.e. the module initializer is executed when a module is imported for the first time.
Initialization should be eager instead, with an explicit start() call once all modules have been registered with the vm.
This would ensure an application finishes initialization correctly and does not error out unexpectedly on, for example, the first request.

Pseudocode:

vm.register_module("a", ...);
vm.register_module("b", ...);
vm.start(callback); // init all modules in the dependency graph, respecting module dependencies

Fix static library build

Installing currently does not work if one wants to include the static library.

Tiro should support two modes: BUILD_SHARED_LIBS: true/false

The static library needs extra care, as it needs to be partially linked: dependencies like absl or fmt should be bundled and their symbols should be hidden.

Details:

Example:

$ ld -Ur --version-script=api.version.gcc  --whole-archive libtiro_static.a --no-whole-archive ../_deps/fmt-build/libfmtd.a [...]

Optional and variadic function arguments

Currently user defined functions can only specify a fixed number of parameters:

fn foo(a, b, c) { ... }

We should at least support optional function parameters and possibly also variadic functions.

Example syntax for optional parameters:

fn dump(value, pretty = false) { ... }

"?" syntax like in TypeScript (e.g. pretty?) is not a good idea here, i think.
The only fitting default value would be null (i do not want an undefined construct exposed to the language).

Do not rely on non-moving object data

Some places in the vm implementation (e.g. hash table) rely on the internal Layout pointer to remain stable while operating on the object. This will break in the future once the gc moves objects around.

The existing code should be fixed.
There should also be infrastructure to ensure that this error is avoided in the future.

Notes:

  • Some functions that are currently methods may have to become static functions instead, as they can no longer work on the raw object.
  • Eventually, it would be nice if those functions could become methods on the stable Handle instead

Optimize binary size a bit

Possible opportunities for saving some code size:

  • Better compression of unicode table in common/text/unicode_data.cpp
    • Lots of space is wasted because all entries use 4 byte code point values. Code point ranges in [0, 256) and [256, 65536) can use a different layout.
    • Note that the source file is generated by a python script (which should also be migrated to cog)
  • Wrapper around absl::flat_hash_set(/table) for maps and sets of Id keys (e.g. InstId). All of those Id types are simple wrappers around integers (usually u32), but their template instantiations seem to be distinct. By creating a wrapper type that is a simple map of integers we could save some code, although probably not that much because the value the value types would still be distinct.
  • Look into the code size of fmt:: symbols

Tools like Bloaty are useful when working on this.

Implement panic stack traces

The exception type needs support for stack traces.
When an exception is thrown, the N topmost tiro function names should be represented in the trace.

Exact positions within those functions (e.g. line numbers) are currently out of scope because the compiler does not yet emit those information.

Gather API Feedback

Use the library in demo projects and/or real world projects

  • Better error messages (error codes are fine, but need a situational cstring message)

Implement missing bytecode instructions

in vm/interpreter.cpp:

// TODO
case BytecodeOp::LSh:
case BytecodeOp::RSh:
case BytecodeOp::BAnd:
case BytecodeOp::BOr:
case BytecodeOp::BXor:
    TIRO_ERROR("Instruction not implemented yet: {}.", op);

better garbage collector

The current garbage collector implementation is trivial (mark and sweep with individual malloc+free calls).
This should be improved, some ideas are written down here.

Make module import eager again

The following code should produce an error:

import does_not_exist;

export func main() {
}

The module import is currently stripped because it is never used.

vm support for exceptions

Exceptions are already supported by the compiler and must be implemented in the vm.

  • Correct unwinding behaviour, i.e. call exception handlers and transport exceptions objects
  • Unhandled exceptions terminate the current coroutine, the exception object is used to set the coroutine's result (to error)
  • Provide a magic std.pcall(fn) (name TBD) function that can catch exceptions thrown by fn

Ensure strings are always UTF-8

Ensure that string objects in the vm are always utf-8 encoded.

This is already the case for strings created from literals, but the C API and dynamic constructors should enforce this as well.

  • VM: Assert that static strings inside bytecode modules use utf-8 encoding
  • C-API: Check string encoding, return error if not utf-8
  • String constructor: Check string encoding, return error if not utf-8 (maybe also provide a non-panicking constructor function)

User guide

A small user guide is required, to document at least the following things:

  • Getting started examples
  • Language overview, grammar rules and semantics
  • Embedding the compiler and vm

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.