Skip to content
/ icy Public

Icy is a whitespace sensitive language which compiles to C++

Notifications You must be signed in to change notification settings

tejasvi/icy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

markless

Embrace Whitespace

Icy lets you skip closing braces and semicolons by applying indentation based deduction rules. Therefore letting you write:

void BFCAllocator::SetSafeFrontier(uint64 count) {
  uint64 current = safe_frontier_.load(std::memory_order_relaxed)
  while (count > current) {
    if (safe_frontier_.compare_exchange_strong(current, count)) {
      retry_helper_.NotifyDealloc()
      return
    else {
      current = safe_frontier_.load(std::memory_order_relaxed)

instead of:

void BFCAllocator::SetSafeFrontier(uint64 count) {
  uint64 current = safe_frontier_.load(std::memory_order_relaxed);
  while (count > current) {
    if (safe_frontier_.compare_exchange_strong(current, count)) {
      retry_helper_.NotifyDealloc();
      return;
    } else {
      current = safe_frontier_.load(std::memory_order_relaxed);
    }
  }
}

Brace the rules

  1. Strings, comments, trailing whitespace and empty lines are ignored.
  2. If next line has higher indentation, both lines are treated as same logical line.
    • ScopeExitGuard(const bool callOnScopeExit_,
                     F &&onScopeExit_,
                     m_callOnScopeExit(callOnScopeExit_),
                     m_onScopeExit(std::forward<F>(onScopeExit_))
  3. If a line ends with an opening brace and next line has exactly one level higher indentation, it marks the start of a block.
    • namespace guard { // Not a block. Must close manually
      if (m_callOnScopeExit) { // Block
          m_onScopeExit()
      std::cout << "Enter"     // Block closed
  4. The line after the next logical line having indentation equal or lower than the block's start, marks the end of the block.
    • ScopeExitGuard(ScopeExitGuard<G> &&other)
          : m_callOnScopeExit(true) { // Block start at logical line's indent 0
        other.m_callOnScopeExit = false
      
      ~ScopeExitGuard() { // Previous block ends
        if (m_callOnScopeExit) {
          m_onScopeExit()
  5. If a logical line has indentation equal or greater than the next line, it is treated as a statement and appended with a semi-colon.
    • The line must not end with { ; , : < ( [ =.
    • Exception for isolated template declarations.
      • template <typename G> // Not a statement
        ScopeExitGuard(ScopeExitGuard<G> &&other)
            : m_callOnScopeExit(true) {
          other.m_callOnScopeExit = false // Statement
          std::cout << "Exit" // Statement
        auto flags = {1, 2, 3}

Extras

  • Icy can seamlessly integrated with existing C++ tooling since the brace and semi-colon addition is done only on the line ends which preserves line and column numbers. TODO: Extensions for popular editors. Should be trivial.
  • Decompilation with icyd involves clang-format with following configuration.
    LambdaBodyIndentation: Signature
    IndentGotoLabels: true
    IndentExternBlock: Indent
    BreakBeforeBraces: Attach
    AllowAllArgumentsOnNextLine: false
    Cpp11BracedListStyle: false
    IndentRequires: true
    IndentWrappedFunctionNames: true
    NamespaceIndentation: All
    UseTab: Never
    CompactNamespaces: false
    
    Closing braces and semi-colons are removed if Icy compiler icyc can deduce them from the indentation of formatted code.

Related works

There have been a few attempts at trimming the C++ syntax but have ended up being too disruptive.

About

Icy is a whitespace sensitive language which compiles to C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages