abhijeetbhagat / charon Goto Github PK
View Code? Open in Web Editor NEWA compiler in Rust for the Tiger language
License: MIT License
A compiler in Rust for the Tiger language
License: MIT License
let function foo() = if 8 then print(\"rust\") else print(\"c++\") in foo() end
creates:
; ModuleID = 'main_mod'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
@.str = private unnamed_addr constant [5 x i8] c"rust\00"
@.str2 = private unnamed_addr constant [4 x i8] c"c++\00"
define i32 @main() {
entry:
call void @foo()
%call = call void @exit(i32 0)
ret i32 0
}
define void @foo() {
ifcont:
%call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i32 0, i32 0))
ret void
}
declare i32 @printf(i8*, ...)
declare i32 @printf1(i8*, ...)
declare void @exit(i32)
Like gcc, don't call printf if the string is empty.
Lifetimes can be used across lexer, parser, TC and trans phases
At the moment there is exit() called before return to avoid segfault since there is no startup code to return to. Probably using gcc to link can add this startup code?
At the moment this will not work:
var a : array := array[1+1] of 0
since 1+1
isn't getting evaluated at compile time.
At the moment, with bluss's advise, the value-type for sym-table is Box trait object.
Instead, implement From/Into traits.
All unit tests are written in the respective modules. Move them module-wise into the test folder.
String handling in the compiler is shitty. Use Cows.
In the parse functions of the if, while and for expressions this needs to be checked. For e.g.
fn parse_if_then_else_expr(&mut self) -> Option<(TType, B<Expr>)>{
//eat 'if'
self.lexer.get_token();
//parse the conditional expr
let opt_tup = self.expr().unwrap();
match self.lexer.curr_token {
Token::Then => {
self.lexer.get_token(); //advance to the next token
let (_, then_expr) = self.expr().unwrap();
match self.lexer.curr_token { // <==Will this always work?
Token::Else => {
self.lexer.get_token(); //advance to the next token
let (_, else_body) = self.expr().unwrap();
return Some((TVoid, B(IfThenElseExpr(opt_tup.1, then_expr, else_body))))
}
_ => {}
}
Some((TVoid, B(IfThenExpr(opt_tup.1, then_expr))))
},
_ => panic!("Expected then after the if expression")
}
}
Get rid of panic!s for error reporting. Follow rustc's approach:
https://github.com/rust-lang/rust/blob/master/src/libsyntax/errors/mod.rs#L104
Different kinds of function bodies need to be unit tested
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.