Giter Site home page Giter Site logo

concrete's Introduction

Concrete (WIP)

Concrete is a statically-typed language, implemented with a bytecode interpreter. Parsing is done using Ply/Sly.

Example

num n = 10
fun fib (num n) -> num {
    if n == 0 return 0 end
    if n == 1 return 1 end
    return fib(n-1) + fib(n-2)
}
print(fib(n)) # 55

fun quadratic(num a, num b, num c, num x) -> num {
    # Nested function
    fun square (num x) -> num {
       return x * x
    }
    num res = square(a) * x + b * x + c
    return res
}

print(QUADRATIC(1,1,1,1)) # 3

About

A potential goal is to make this a lightweight embedded language, similar to Lua, but statically typed.

Compiler code likely to be reduced to RPython or rewritten in C.

Codebase is WIP refactoring, transforming from an experimental / hobby project, to something more robust.

Usage

Usage: ccr [OPTIONS] [FILE]

Options:
  -i, --interactive  Run in interactive mode
  -s, --string TEXT  Interpret a string
  -h, --help         Display help information
  -d, --debug        Enable debug mode
  -p, --parse        Enable parse mode
  -c, --compile      Enable compiler mode
  -l, --lex          Enable lex mode

Testing

Run tests with

pytest

Typing

Illustrations of the static typing:

# Assignment type errors
# num x = 1 # TypeError: Cannot redefine x -- already defined
# x = "a" # TypeError:30:2 Cannot assign x of num to expression of type str

# Scoping type errors
# num res = SQUARE(2) # TypeError: unable to find function SQUARE in any scope.

# Type checking
# str bad_return_type = inc(1) # TypeError:36:2 Cannot assign bad_return_type of str to expression of type num
# num bad_input_type = inc("a") # TypeError:inc: Expected num for v; got str

# TypeError:52:6 Function bad of return type str but got expression of num
# fun bad () -> str {
#     return 1
# }

Known issues

  • [MAYBE NOT BUG] Lexical scoping of function parameters when the symbol exists in global scope
  • [FIXED] Bug in conditionals always taking first case in function scope
  • [FIXED] Bug in return type when recursive function calls involved in an expression

concrete's People

Contributors

apsz3 avatar

Watchers

 avatar

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.