Code Monkey home page Code Monkey logo

simplecompiler's People

Contributors

glaebhoerl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

simplecompiler's Issues

stage 2: the compiler available at runtime

  • Finish stage #1


  • Split compiler into lib + app
  • Link GHC RTS into compiled apps
  • Link compiler lib itself into compiled apps
  • Do some kind of JITing in the compiled app, make sure it works(?)

  • What other preconditions does this have??
  • Expose a compile/optimize function (intrinsic?) to the compiled app
    • (decide wtf to call it...)
  • Try it and make sure it works

  • Decide what to do for stage 3

Big list of potential features - language

  • Everything-is-an-expression
  • ASCII strings
  • {Int,UInt}{8,16,32,64}
  • Float{32,64}
  • Structs (nominal products)
  • Enums (nominal sums) with simple switch
  • Never (uninhabited type)
  • Arrays
  • Shared mutable references
  • Type aliases
  • Irrefutable destructuring
  • "Method syntax"

  • inout parameters
  • Pattern matching
  • Tuples (structural products)
  • Structural sums
  • Unicode strings
  • Generic functions (top level, first order, "prenex")
  • Generic types (first order)
  • "Type classes" / interfaces
  • Recursive types
  • Iterators, foreach
  • Ranges
  • Self-modifying functions (function!())
  • A module system for namespacing
  • "Syntactic" operator overloading

  • Unbounded Int, UInt, Float
  • Complex numbers
  • "Associated types"
  • "Object types" (like trait objects)
  • Existential types
  • Polymorphic recursion
  • Generic functions (higher-order, "higher rank")
  • Generic types (higher-order, "higher kinded")
  • A kind system
  • Variadic types ([type] kind)
  • Generic modules
  • Privacy
  • Effect tracking
  • unsafe / trusted
  • Threads
  • Dynamic typing, reflection

TODO

  • Docs
  • Tests

Features

  • Implement functions
    • Parsing
    • Pretty-printing
    • Name resolution
    • Typechecking
    • IR
    • LLVM
  • Need to enforce that functions actually return something!! :(
  • Implement a string type
  • Better error reporting
    • Source location tracking
      • Token
      • AST
      • Name.Error
      • Type.Error
    • <?> or whatever in AST parser
    • Store source Text in metadata?
    • instance Render Token.Error
    • instance Render AST..Error
    • instance Render Name.Error
    • instance Render Type.Error
    • Anything else....?
  • Pretty printing of AST
  • More analyses / transformations in IR?

Odds and ends

  • Re-add validation for Type
  • Validation of IR should validate Functions
  • Make validation failures print the thing that failed to validate
  • Bikeshedding and other cleanup of Pretty
  • instance Render IR.Function
  • nicer pretty-printing of types
  • AST could store full Expressions (or other nodes) instead of just names in some places for finer-grained location metadata

Bugs

  • Less hacky newline handling
  • Properly handle exceptions in Main
  • Fix - parsing ambiguity (unary vs. binary vs. literal)
  • Fix Tardis-related laziness hacks in IR
  • Fix dead-code-related bugs in IR generation
  • Refactor handling of precedence in AST (and fix for &&, ||)?
  • Improve handling of operations in LLVM to avoid UB on overflow/div-by-zero/etc.
  • function isBuzz(number: Int) returns isBuzz validation error
  • IR validation error due to function w/ if { return x } else { return x } and implicitly inserted unit return
  • Name doesn't record metadata/location for function arguments/returns (and maybe others)

Facultative

  • Implement break
  • anonymous scopes
  • unify say() and write()? ask() for strings?
  • make comparison operators polymorphic?
  • Either -> Validation?
  • Bool literals
  • Unit in AST
  • function types in syntax, C-level HOFs?
  • type annotations on lets
  • type annotations in expressions
  • add more pretty-printing styles (e.g. name-based, scope-based, type-based semantic highlighting); allow selecting w/ command-line flag?
  • add continue

Refactor

  • Update to GHC 8.6, LLVM 7
  • enable StrictData?
  • check assignments in Name, get rid of NameWith? would invalidate Name.validate
  • rename repo
  • use unused instead of _ <-
  • make use of modifyM variants directly returning the modified state, where appropriate
  • text-path-utf8?
  • safe-exceptions?
  • organize Token
  • try DeriveAny again?
  • can we use DerivingVia? or QuantifiedConstraints?
  • BlockArguments!!
  • our own Loc type?
  • make the error-type in Main be a Doc rather than Text?
  • some kind of multiplatey abstraction?
  • add a method in Render to customize how lists of the type are rendered, get rid of the flexible list instances?
    • instance Render a => Render (Maybe a)?
  • style consistency: where always trailing
  • style: always require newline after ->/=...?
  • do something about all the warnings
  • keep a stack of metadata instead of a scalar for better robustness?
  • factor out a MonadMetadata or something?
  • generalize the parser itself over arbitrary Monoid metadata?
  • collapse LLVM.FirstState and SecondState, with just the instances differing?
  • DisambiguateRecordFields?
  • StateT -> ReaderT
  • explore https://github.com/lamdu/syntax-tree ?

FUTURE

  • IRBuilder?
  • SSA?
  • Change IR to graph-based Thorin-style
  • Expression language
  • Bidirectional typechecking
  • Unification
  • Nonlocal breaks, breaks returning values
  • Struct types
  • Sum types, simple switches
  • Stack closures
  • Stack references (lifetime checking?)
  • Arrays, stack slices
  • Heap allocation, reference counting, heap-allocated strings, arrays, closures

stage 1: a simple compiler

  • Make a Stack project w/ the chosen dependencies
  • Make sure they all resolve & build etc.
  • Figure out what the initial minimal language will be?
  • Make sure LLVM still works w/ the OrcJIT example
  • Figure out what a concrete syntax tree should look like as a Haskell type

  • Write some types?
  • Lex something
  • Parse something
  • Resolve names
  • Typecheck something
  • Translate to an IR (ANF w/ basic blocks & basic block args?)
    • BBs or EBBs? probably BBs for now to simplify translation to LLVM
  • Generate some code
  • Output a binary
  • Make sure it actually runs & works

  • Write tests for everything! http://teh.id.au/posts/2017/06/07/round-trip-property/index.html
    • Write pretty printers
      • AST
      • IR
      • Error messages
    • Write well-formedness validators
    • Write a typechecker for the IR as well
    • Write an evaluator
    • Write fizzbuzz
  • Write a usable CLI
  • Make it JIT
  • Go back and fix the fixable FIXMEs and TODOs
  • Write a README w/ overview

two types: Int, Bool
arithmetic and comparison operators
if, while; forever/break?
let, var
read(), write()
mutation (assignment)
no functions yet

Example program:

 var n = 0
 forever {
     write(n)
     let m = read()
     if m == 0 {
         return
     }
     n = n + m
 }

Big list of potential features - implementation

  • Track source locations throughout
  • Warnings for: dead code, unused mutability, ...
  • Pragmas: inline, specialize...?
  • Memory management (RC, CoW?)
  • Evaluator / interpreter
  • Actual optimizations in the frontend, on IR (with hoopl?)

  • Cross-linked interactive HTML output w/ full types etc.
  • DWARF
  • REPL
  • "IDE support"
  • Incremental compilation (caching)
  • Parallelized compiler
  • Type errors with counterexamples
  • -fdefer-type-errors
  • Literate programming
  • Stack traces on abort

Technical debt

  • Use precise version bounds in the .cabal file
  • Give names to the productions in the grammar for better error messages
  • Use explicit export lists, hide modules' internal implementation details

Performance

  • Use interned strings?
  • Use things like Vector Statement rather than [Statement]?

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.