tdp2110 / haskelltiger Goto Github PK
View Code? Open in Web Editor NEWModern Compiler Implementation in ML, in Haskell
License: Boost Software License 1.0
Modern Compiler Implementation in ML, in Haskell
License: Boost Software License 1.0
do they blow up the compiler? should tiger semantics support them?
I bet now many of these can be sugared in do
-notation
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")
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
there's a hack in the frame class, setting the frame size to 1024. obvz this needs to change
I'm seeing a bunch of redundant jumps, eg, at 7ee3311, compiling examples/fact.tiger I see
...
jmp .L16
.L16:
...
this is supposed to be a safe language!
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
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
these will be reserved for the compiler, and we don't need UB in Tiger.
page 162 of mciiml describes this
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
examples/pair1.tiger prints 0. it should print 1.
we're conservatively adding too many edges. see the liveness chapter
these should only come from nil
record creation
right now we use a constant function XD
for visualizing Tree IR
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.