1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 18:18:51 +03:00
mal/impls/swift/step0_repl.swift
Joel Martin 8a19f60386 Move implementations into impls/ dir
- Reorder README to have implementation list after "learning tool"
  bullet.

- This also moves tests/ and libs/ into impls. It would be preferrable
  to have these directories at the top level.  However, this causes
  difficulties with the wasm implementations which need pre-open
  directories and have trouble with paths starting with "../../". So
  in lieu of that, symlink those directories to the top-level.

- Move the run_argv_test.sh script into the tests directory for
  general hygiene.
2020-02-10 23:50:16 -06:00

65 lines
1.6 KiB
Swift

//******************************************************************************
// MAL - step 0 - repl
//******************************************************************************
// This file is automatically generated from templates/step.swift. Rather than
// editing it directly, it's probably better to edit templates/step.swift and
// regenerate this file. Otherwise, your change might be lost if/when someone
// else performs that process.
//******************************************************************************
import Foundation
// Parse the string into an AST.
//
private func READ(str: String) -> String {
return str
}
// Walk the AST and completely evaluate it, handling macro expansions, special
// forms and function calls.
//
private func EVAL(ast: String) -> String {
return ast
}
// Convert the value into a human-readable string for printing.
//
private func PRINT(exp: String) -> String {
return exp
}
// Perform the READ and EVAL steps. Useful for when you don't care about the
// printable result.
//
private func RE(text: String) -> String {
let ast = READ(text)
let exp = EVAL(ast)
return exp
}
// Perform the full READ/EVAL/PRINT, returning a printable string.
//
private func REP(text: String) -> String {
let exp = RE(text)
return PRINT(exp)
}
// Perform the full REPL.
//
private func REPL() {
while true {
if let text = _readline("user> ") {
print("\(REP(text))")
} else {
print("")
break
}
}
}
func main() {
load_history_file()
REPL()
save_history_file()
}