Skip to content

Commit

Permalink
optimization: conditionally remove some debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-rollin committed Apr 8, 2015
1 parent 132f9c9 commit 2c4b8bd
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
8 changes: 5 additions & 3 deletions swift/step5_tco.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let INDENT_TEMPLATE = "|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|"
var indent = String()

let kSymbolDef = MalSymbol(symbol: "def!")
let kSymbolDo = MalSymbol(symbol: "do")
Expand Down Expand Up @@ -121,13 +122,14 @@ func eval_ast(ast: MalVal, env: Environment) -> MalVal {
// forms and function calls.
//
func EVAL(var ast: MalVal, var env: Environment) -> MalVal {
var x = EVAL_Counter()
let x = EVAL_Counter()
if EVAL_level > EVAL_leval_max {
return MalError(message: "Recursing too many levels (> \(EVAL_leval_max))")
}

let indent = INDENT_TEMPLATE.substringToIndex(
advance(INDENT_TEMPLATE.startIndex, EVAL_level, INDENT_TEMPLATE.endIndex))
if DEBUG_EVAL {
indent = prefix(INDENT_TEMPLATE, EVAL_level)
}

while true {
if is_error(ast) { return ast }
Expand Down
8 changes: 5 additions & 3 deletions swift/step6_file.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let INDENT_TEMPLATE = "|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|"
var indent = String()

let kSymbolArgv = MalSymbol(symbol: "*ARGV*")
let kSymbolDef = MalSymbol(symbol: "def!")
Expand Down Expand Up @@ -123,13 +124,14 @@ func eval_ast(ast: MalVal, env: Environment) -> MalVal {
// forms and function calls.
//
func EVAL(var ast: MalVal, var env: Environment) -> MalVal {
var x = EVAL_Counter()
let x = EVAL_Counter()
if EVAL_level > EVAL_leval_max {
return MalError(message: "Recursing too many levels (> \(EVAL_leval_max))")
}

let indent = INDENT_TEMPLATE.substringToIndex(
advance(INDENT_TEMPLATE.startIndex, EVAL_level, INDENT_TEMPLATE.endIndex))
if DEBUG_EVAL {
indent = prefix(INDENT_TEMPLATE, EVAL_level)
}

while true {
if is_error(ast) { return ast }
Expand Down
8 changes: 5 additions & 3 deletions swift/step7_quote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let INDENT_TEMPLATE = "|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|"
var indent = String()

let kSymbolArgv = MalSymbol(symbol: "*ARGV*")
let kSymbolConcat = MalSymbol(symbol: "concat")
Expand Down Expand Up @@ -229,13 +230,14 @@ func eval_ast(ast: MalVal, env: Environment) -> MalVal {
// forms and function calls.
//
func EVAL(var ast: MalVal, var env: Environment) -> MalVal {
var x = EVAL_Counter()
let x = EVAL_Counter()
if EVAL_level > EVAL_leval_max {
return MalError(message: "Recursing too many levels (> \(EVAL_leval_max))")
}

let indent = INDENT_TEMPLATE.substringToIndex(
advance(INDENT_TEMPLATE.startIndex, EVAL_level, INDENT_TEMPLATE.endIndex))
if DEBUG_EVAL {
indent = prefix(INDENT_TEMPLATE, EVAL_level)
}

while true {
if is_error(ast) { return ast }
Expand Down
8 changes: 5 additions & 3 deletions swift/step8_macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let INDENT_TEMPLATE = "|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|"
var indent = String()

let kSymbolArgv = MalSymbol(symbol: "*ARGV*")
let kSymbolConcat = MalSymbol(symbol: "concat")
Expand Down Expand Up @@ -255,13 +256,14 @@ func eval_ast(ast: MalVal, env: Environment) -> MalVal {
// forms and function calls.
//
func EVAL(var ast: MalVal, var env: Environment) -> MalVal {
var x = EVAL_Counter()
let x = EVAL_Counter()
if EVAL_level > EVAL_leval_max {
return MalError(message: "Recursing too many levels (> \(EVAL_leval_max))")
}

let indent = INDENT_TEMPLATE.substringToIndex(
advance(INDENT_TEMPLATE.startIndex, EVAL_level, INDENT_TEMPLATE.endIndex))
if DEBUG_EVAL {
indent = prefix(INDENT_TEMPLATE, EVAL_level)
}

while true {
if is_error(ast) { return ast }
Expand Down
8 changes: 5 additions & 3 deletions swift/step9_try.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let INDENT_TEMPLATE = "|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|"
var indent = String()

let kSymbolArgv = MalSymbol(symbol: "*ARGV*")
let kSymbolCatch = MalSymbol(symbol: "catch*")
Expand Down Expand Up @@ -257,13 +258,14 @@ func eval_ast(ast: MalVal, env: Environment) -> MalVal {
// forms and function calls.
//
func EVAL(var ast: MalVal, var env: Environment) -> MalVal {
var x = EVAL_Counter()
let x = EVAL_Counter()
if EVAL_level > EVAL_leval_max {
return MalError(message: "Recursing too many levels (> \(EVAL_leval_max))")
}

let indent = INDENT_TEMPLATE.substringToIndex(
advance(INDENT_TEMPLATE.startIndex, EVAL_level, INDENT_TEMPLATE.endIndex))
if DEBUG_EVAL {
indent = prefix(INDENT_TEMPLATE, EVAL_level)
}

while true {
if is_error(ast) { return ast }
Expand Down
8 changes: 5 additions & 3 deletions swift/stepA_mal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let INDENT_TEMPLATE = "|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|"
var indent = String()

let kSymbolArgv = MalSymbol(symbol: "*ARGV*")
let kSymbolCatch = MalSymbol(symbol: "catch*")
Expand Down Expand Up @@ -257,13 +258,14 @@ func eval_ast(ast: MalVal, env: Environment) -> MalVal {
// forms and function calls.
//
func EVAL(var ast: MalVal, var env: Environment) -> MalVal {
var x = EVAL_Counter()
let x = EVAL_Counter()
if EVAL_level > EVAL_leval_max {
return MalError(message: "Recursing too many levels (> \(EVAL_leval_max))")
}

let indent = INDENT_TEMPLATE.substringToIndex(
advance(INDENT_TEMPLATE.startIndex, EVAL_level, INDENT_TEMPLATE.endIndex))
if DEBUG_EVAL {
indent = prefix(INDENT_TEMPLATE, EVAL_level)
}

while true {
if is_error(ast) { return ast }
Expand Down
8 changes: 5 additions & 3 deletions swift/templates/step.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ let INDENT_TEMPLATE = "|----|----|----|----|----|----|----|----|" +
"----|----|----|----|----|----|----|----|----|----|----|" + // malstep(5,6,7,8,9,A)
"----|----|----|----|----|----|----|----|----|----|----|" + // malstep(5,6,7,8,9,A)
"----|----|----|----|----|----|----|----|----|----|----|" // malstep(5,6,7,8,9,A)
var indent = String() // malstep(5,6,7,8,9,A)
// malstep(5,6,7,8,9,A)
let kSymbolArgv = MalSymbol(symbol: "*ARGV*") // malstep(6,7,8,9,A)
let kSymbolCatch = MalSymbol(symbol: "catch*") // malstep(9,A)
Expand Down Expand Up @@ -340,13 +341,14 @@ func EVAL(ast: MalVal) -> MalVal {
return ast // malstep(1)
} // malstep(1)
func EVAL(var ast: MalVal, var env: Environment) -> MalVal { // malstep(2,3,4,5,6,7,8,9,A)
var x = EVAL_Counter() // malstep(5,6,7,8,9,A)
let x = EVAL_Counter() // malstep(5,6,7,8,9,A)
if EVAL_level > EVAL_leval_max { // malstep(5,6,7,8,9,A)
return MalError(message: "Recursing too many levels (> \(EVAL_leval_max))") // malstep(5,6,7,8,9,A)
} // malstep(5,6,7,8,9,A)
// malstep(5,6,7,8,9,A)
let indent = INDENT_TEMPLATE.substringToIndex( // malstep(5,6,7,8,9,A)
advance(INDENT_TEMPLATE.startIndex, EVAL_level, INDENT_TEMPLATE.endIndex)) // malstep(5,6,7,8,9,A)
if DEBUG_EVAL { // malstep(5,6,7,8,9,A)
indent = prefix(INDENT_TEMPLATE, EVAL_level) // malstep(5,6,7,8,9,A)
} // malstep(5,6,7,8,9,A)
// malstep(5,6,7,8,9,A)
while true { // malstep(5,6,7,8,9,A)
if is_error(ast) { return ast } // malstep(2,3,4,5,6,7,8,9,A)
Expand Down

0 comments on commit 2c4b8bd

Please sign in to comment.