Coder Social home page Coder Social logo

charon's People

Contributors

abhijeetbhagat avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

lance2088

charon's Issues

Two print calls create two different prototypes in the generated IR

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)

Verify parsing of conditionals always requires matching on curr_token instead of get_token()

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")
        }
    }

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.