Unary Operations
This commit is contained in:
@@ -5,6 +5,9 @@ import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "rxcc",
|
||||
platforms: [
|
||||
.macOS(.v13)
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
||||
// Targets can depend on other targets in this package and products from dependencies.
|
||||
|
||||
@@ -234,7 +234,7 @@ func getTestFiles() -> [TestFile] {
|
||||
var testFiles: [TestFile] = [TestFile]()
|
||||
|
||||
let fileManager = FileManager.default
|
||||
let path = "c/tests/stage_1"
|
||||
let path = "c/tests/stage_2"
|
||||
|
||||
do {
|
||||
let validItems = try fileManager.contentsOfDirectory(atPath: path + "/valid")
|
||||
@@ -358,6 +358,36 @@ func generateOutput(_ node: SyntaxTreeNode) -> String {
|
||||
text += " movl $\(returnValue), %eax\n ret\n"
|
||||
break
|
||||
|
||||
case .UnaryOperation:
|
||||
if node.children.count != 2 {
|
||||
print("\(node.variant) must have two child nodes")
|
||||
}
|
||||
let operation: SyntaxTreeNode = node.children[0]
|
||||
let expression: SyntaxTreeNode = node.children[1]
|
||||
|
||||
|
||||
switch operation.variant {
|
||||
case .BitwiseCompliment:
|
||||
text += String(~Int(generateOutput(expression))!)
|
||||
break
|
||||
|
||||
case .Negation:
|
||||
text += String(-Int(generateOutput(expression))!)
|
||||
break
|
||||
|
||||
case .LogicalNegation:
|
||||
text += String(Int(generateOutput(expression))! == 0 ? "1" : "0")
|
||||
break
|
||||
|
||||
default:
|
||||
print("\(node.variant): Unknown unary operation \"\(operation.variant)\"")
|
||||
}
|
||||
break
|
||||
|
||||
case .Negation, .BitwiseCompliment, .LogicalNegation:
|
||||
text += node.value
|
||||
break
|
||||
|
||||
case .LiteralInteger:
|
||||
text += node.value
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user