Skip to content
chatur edited this page Jan 27, 2012 · 20 revisions

Built-In Types

  • How are strings implemented? Does Clay support UTF8?

    Currently Clay strings are just mutable byte vectors stored on the heap. In the future, strings will be immutable with better support for UTF8.

  • How do I get the largest value for an integer type?

    Use Greatest(Int), Greatest(Int64), etc.

Variants

  • How much space (in bytes) does a variant occupy?

    Variants are implemented as tag + value. Since all values of the variant have the same size, the size of the variant is machine word size (for the tag) + size of largest variant member.

  • How do I dynamically dispatch the appropriate method for a variant?

    Use the asterisk to dispatch on a variant value: f(*v). For e.g., if you have a variant with two members, and a function overloaded for both member types:

    variant Shape (Circle, Square);
    define draw;
    overload draw(c:Circle) {...}
    overload draw(s:Square) {...}
    

    Then, to dynamically dispatch on a value shape of type Shape:

    draw(*shape);  // where shape = Shape(...)
    
  • Are variant types closed or open?

    Variants are open so you can add new member types to a variant after it has been defined. For e.g. if you have a variant defined as variant Shape (Circle, Square);, you can expand it to include a new member with instance Shape Triangle;

Performance

  • Benchmarks are slower than equivalent C or C++ code

    Clay's library includes bounds check and integer overflow assertions by default, which adds about 10% overhead in typical code. Make sure you test with -Dclay.DisableAssertions to disable all assertions, or -Dclay.DisableAssertions.boundsChecks -Dclay.DisableAssertions.overflowChecks to disable only bounds and overflow check assertions, to get a fair comparison.

Building Clay

  • How do I build a debug or release version of Clay?

    When running cmake, set the CMAKE_BUILD_TYPE attribute to Debug or Release as needed. For e.g.: cmake -DCMAKE_BUILD_TYPE=Debug ..

  • Clay complains about parser errors on /* tokens

    Older versions of GCC have a compiler bug that breaks Clay's parser. Try updating your GCC, or using Clang.

  • Clay won't compile because it says it requires LLVM 3.0, even though I have LLVM 3.x

    LLVM minor revisions and developer versions are not source compatible. Only LLVM 3.0 (not 3.0svn) release is currently supported.

Clone this wiki locally