Skip to content

Commit

Permalink
Closes #150. Added bitwise stl functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
AZHenley committed Apr 28, 2019
1 parent 6251bb2 commit f6dfcca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion builtin/stl.knox
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// stl should be a module, not a class.
// TODO: stl should be a module, not a class.
class stl {
func print(x : string) void {}
func range(start : int, end : int, step : int) [int] { return [0]; }

func and(x : int, y : int) int { return 0; }
func or(x : int, y : int) int { return 0; }
func not(x : int) int { return 0; }
func xor(x : int, y : int) int { return 0; }
func left(x : int, y : int) int { return 0; }
func right(x : int, y : int) int { return 0; }
}
13 changes: 13 additions & 0 deletions emitter/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,20 @@ func funcCall(node *ast.Node) string {
funcName = "printf"
argList = expr(&node.Children[1])
return funcName + "(\"%s\", " + argList + ");"
case "and":
return "(" + expr(&node.Children[1]) + " & " + expr(&node.Children[2]) + ")"
case "or":
return "(" + expr(&node.Children[1]) + " | " + expr(&node.Children[2]) + ")"
case "not":
return "(~" + expr(&node.Children[1]) + ")"
case "left":
return "(" + expr(&node.Children[1]) + " << " + expr(&node.Children[2]) + ")"
case "right":
return "(" + expr(&node.Children[1]) + " >> " + expr(&node.Children[2]) + ")"
case "xor":
return "(" + expr(&node.Children[1]) + " ^ " + expr(&node.Children[2]) + ")"
}

}

// If a method.
Expand Down

0 comments on commit f6dfcca

Please sign in to comment.