Code Monkey home page Code Monkey logo

moco's People

Contributors

cpfr avatar einjohn avatar lummax avatar skuzzle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

moco's Issues

Error reporting

In many cases the exception classes do not receive an ASTNode object, therefore the error reporting can not provide a line number of the error (which is not very helpful in many cases):

ResolveVisitor caught error in null: ...

instead of

ResolveVisitor caught error in line 7, char 13: ...

The problem is that those exceptions are thrown inside the Scope class, which does not have any node objects associated, thus there is no node to pass to the exception object.

Any suggestions are appreciated.

Returning from if-Statement

Code generation for if-Statements seems broken. The following code produces the lli error

lli: C:\Users\Simon\Documents\Java\moco\target\test-classes\testPrograms\if.ll:110:1: error: expected instruction opcode

print(foo(true))
print(foo(false))

String foo(Bool cond):
    if cond:
        return "a"
    else:
        return "b"

Generated code:

define i8* @M.if.F.foo$M.std.C.String$M.Bool.C.Bool(%M.Bool.C.Bool* %M.if.V.cond$M.Bool.C.Bool)  {
    entry:
    %_unnamed_0 = getelementptr inbounds %M.Bool.C.Bool* %M.if.V.cond$M.Bool.C.Bool, i32 0,i32 1
    %_unnamed_1 = load i1* %_unnamed_0
    br i1 %_unnamed_1, label %if0.true, label %if0.false
    if0.true:
    ret i8* getelementptr inbounds ([2 x i8]* @.0, i32 0, i32 0)
    br label %if0.end
    if0.false:
    ret i8* getelementptr inbounds ([2 x i8]* @.1, i32 0, i32 0)
    br label %if0.end
    if0.end:
}

I'm not sure wether this applies to the current master but the code generation for if-statements seems not to have changed recently.

EmptyStackException when using Expressions without assigning their value to a variable

I encountered a bug in the current master revision of the Monty compiler (although this also seems to be broken in earlier versions). The following Monty input program produces an EmptyStackException in the CodeGenerationVisitor:

class Person:
    + Int age():
        return 8

Int x := Person().age()

While the following Monty program works fine:

class Person:
    + Int age():
        return 8

Person p := Person()
Int x := p.age()

It seems like expressions which are not assigned to a variable are not correctly pushed to the stack. The corresponding stack trace looks like the following:

java.util.EmptyStackException
        at java.util.Stack.peek(Stack.java:102)
        at java.util.Stack.pop(Stack.java:84)
        at de.uni.bremen.monty.moco.visitor.CodeGenerationVisitor.visit(CodeGenerationVisitor.java:200)
        at de.uni.bremen.monty.moco.ast.statement.Assignment.visit(Assignment.java:84)
        at de.uni.bremen.monty.moco.visitor.BaseVisitor.visitDoubleDispatched(BaseVisitor.java:72)
        at de.uni.bremen.monty.moco.visitor.CodeGenerationVisitor.visit(CodeGenerationVisitor.java:191)
        at de.uni.bremen.monty.moco.ast.Block.visit(Block.java:106)
        at de.uni.bremen.monty.moco.visitor.BaseVisitor.visitDoubleDispatched(BaseVisitor.java:72)
        at de.uni.bremen.monty.moco.ast.declaration.ModuleDeclaration.visitChildren(ModuleDeclaration.java:99)
        at de.uni.bremen.monty.moco.visitor.BaseVisitor.visit(BaseVisitor.java:128)
        at de.uni.bremen.monty.moco.ast.Package.visitChildren(Package.java:77)
        at de.uni.bremen.monty.moco.visitor.BaseVisitor.visit(BaseVisitor.java:425)
        at de.uni.bremen.monty.moco.visitor.CodeGenerationVisitor.visit(CodeGenerationVisitor.java:179)
        at de.uni.bremen.monty.moco.ast.Package.visitChildren(Package.java:74)
        at de.uni.bremen.monty.moco.visitor.BaseVisitor.visit(BaseVisitor.java:425)
        at de.uni.bremen.monty.moco.visitor.CodeGenerationVisitor.visit(CodeGenerationVisitor.java:174)
        at de.uni.bremen.monty.moco.ast.Package.visit(Package.java:68)
        at de.uni.bremen.monty.moco.visitor.BaseVisitor.visitDoubleDispatched(BaseVisitor.java:72)
        at de.uni.bremen.monty.moco.Main.visitVisitors(Main.java:127)
        at de.uni.bremen.monty.moco.Main.main(Main.java:246)

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.