Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unary negation #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions eplan.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.beust:jcommander:1.58" level="project" />
<orderEntry type="library" name="Maven: com.github.vbmacher:java-cup-runtime:11b-20160615" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Maven: io.javaslang:javaslang:2.0.4" level="project" />
<orderEntry type="library" name="Maven: io.javaslang:javaslang-match:2.0.4" level="project" />
<orderEntry type="library" name="Maven: io.javaslang:javaslang-render:2.0.0" level="project" />
<orderEntry type="library" name="Maven: org.bytedeco.javacpp-presets:llvm:3.8.0-1.2" level="project" />
<orderEntry type="library" name="Maven: org.bytedeco:javacpp:1.2" level="project" />
<orderEntry type="library" name="Maven: org.bytedeco.javacpp-presets:llvm:linux-x86_64:3.8.0-1.2" level="project" />
</component>
</module>
1 change: 1 addition & 0 deletions src/main/cup/parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ term ::=

factor ::=
LITNUM:x {: RESULT = new ExpNum(x); :}
| MINUS factor:x {: RESULT = new ExpNegate(x); :}
| LPAREN exp:x RPAREN {: RESULT = x; :}
;
34 changes: 34 additions & 0 deletions src/main/java/absyn/ExpNegate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package absyn;

import javaslang.collection.Tree;
import org.bytedeco.javacpp.LLVM;

import static org.bytedeco.javacpp.LLVM.*;


public class ExpNegate extends Exp {
public final Exp e;

public ExpNegate(Exp e) {
this.e = e;
}


@Override


public LLVMValueRef codegen(LLVMModuleRef module, LLVMBuilderRef builder) {
final LLVMValueRef v_e = e.codegen(module, builder);
final LLVMValueRef zero = LLVMConstReal(LLVMDoubleType(), 0);
return LLVMBuildFSub(builder, zero, v_e, "subtmp");

}


@Override


public Tree.Node<String> toTree() {
return Tree.of("ExpNegate", e.toTree());
}
}