Coder Social home page Coder Social logo

tdp2110 / haskelltiger Goto Github PK

View Code? Open in Web Editor NEW
18.0 18.0 0.0 888 KB

Modern Compiler Implementation in ML, in Haskell

License: Boost Software License 1.0

Haskell 87.86% Yacc 3.21% CMake 0.11% C++ 2.02% Python 2.88% Lex 3.92%
compiler compilers haskell

haskelltiger's People

Contributors

tdp2110 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

haskelltiger's Issues

better feedback on parse errors

for example, forget a semicolon as in here?

let
    var str := "hello world!"
in
    print(str)
    print(itoa(size(str)))
end

you may get the following message (which doesn't mention semicolons)

Parse Error at token (Lexeme class=ID "print", posn=5:5, string="print")

refactor Semant.allocLocal

we shouldn't need to pattern match on the result at call sites -- this should never give an error. we should pattern match in the function, asserting the happy path

set proper stack size

there's a hack in the frame class, setting the frame size to 1024. obvz this needs to change

failed codegen in factorial:

as of daf94ee, compiling

    function fact(n: int) : int =
        if n <= 0 then
            1
        else
            n * fact(n - 1)

gives:

.L14:
        push rsp                 ; (fact,line 2, col 5)
        mov rbp, rsp
        sub rsp, 8
        mov rax, rdi
        mov qword ptr [rbp-1], rbx
        mov qword ptr [rbp-2], rbp
        mov qword ptr [rbp-3], r12
        mov qword ptr [rbp-4], r13
        mov qword ptr [rbp-5], r14
        mov qword ptr [rbp-6], r15
        mov rax, 0
        cmp rax, rax
        jle .L15
        jmp .L16
.L16:
        mov r15, rax
        mov r14, [rbp+0]
        mov rbx, 1
        sub rax, rbx
        lea r13, [rip + .L14]
        mov r12, rax            ; caller saves
        mov rbx, rdx            ; caller saves
        mov rbx, rdi            ; caller saves
        mov qword ptr [rsp - 0], r14
        mov rdi, rax
        call r13
        mov rbx, rax
        mov rax, r12            ; caller saves
        mov rdx, rbx            ; caller saves
        mov rdi, rbx            ; caller saves
        mov rax, r15
        imul rax, rbx
.L17:
        mov rbx, qword ptr [rbp-1]
        mov rbp, qword ptr [rbp-2]
        mov r12, qword ptr [rbp-3]
        mov r13, qword ptr [rbp-4]
        mov r14, qword ptr [rbp-5]
        mov r15, qword ptr [rbp-6]
        jmp .L18
.L15:
        mov rax, 1
        jmp .L17
.L18:
        add rsp, 8
        pop rbp
        ret

closure codegen is horked

eg:

let
    var x := 42
    function f(y: int) = x + y
in
    f(x)
end

gives

.L14:
        push rsp                 ; (f,line 3, col 5)
        mov rbp, rsp
        mov rax, [rbp+0]
        mov rax, [rax-1]
        add rax, rdi
        jmp .L15
.L15:
        pop rbp
        ret

example which infinite-loops the compiler:

it's almost examples/sumList, just without recursion. (interestingly, with recursion, we don't infinite-loop!)

let
    type IntList = { head: int, tail: IntList }
    var nilIntList : IntList := nil
    function sum(xs : IntList) : int = if xs = nilIntList then 0 else xs.head /*+ sum(xs.tail)*/
    var xs := IntList { head=0
                      , tail=IntList { head=1
                                     , tail=IntList { head=2
                                                    , tail=nilIntList } } }
in
    print(itoa(sum(xs)))
end

failed codegen from view shift

for example, consider:

let
    var x := 42
    function f(x: int) = x + 1
in
    f(x)
end

as of 3dcebc2, we compile to:

.L14:
        push rsp                 ; (f,line 3, col 5)
        mov rbp, rsp
        mov rbx, 1
        add rax, rbx
        jmp .L15
.L15:
        pop rbp
        ret

without register allocation we get:

.L14:
        push rsp                 ; (f,line 3, col 5)
        mov rbp, rsp
        mov t39, rdi
        mov t42, rbx
        mov t43, rbp
        mov t44, r12
        mov t45, r13
        mov t46, r14
        mov t47, r15
        mov t56, 1
        mov rax, t38
        add rax, t56
        mov t55, rax
        mov t41, t55
        mov rbx, t42
        mov rbp, t43
        mov r12, t44
        mov r13, t45
        mov r14, t46
        mov r15, t47
        mov rax, t41
        jmp .L15
.L15:
        pop rbp
        ret

something about the view shift (moving formal parameters to temps inside the function body) isn't quite working: rdi (first formal parameter) gets moved to t39, but t38 is moved to rax and subsequently incremented.

stack ptr adjustment could be smaller

we currently use maxCallArgs as an input to the stack size setting, but this is overly conservative considering a large number of the first few args to any function are passed in registers

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.