Merge pull request #380 from bjh21/bjh21-bbc-basic
[jackhill/mal.git] / vb / step1_read_print.vb
1 Imports System
2 Imports System.IO
3 Imports Mal
4 Imports MalVal = Mal.types.MalVal
5
6 Namespace Mal
7 Class step1_read_print
8 ' read
9 Shared Function READ(str As String) As MalVal
10 Return reader.read_str(str)
11 End Function
12
13 ' eval
14 Shared Function EVAL(ast As MalVal, env As String) As MalVal
15 Return ast
16 End Function
17
18 ' print
19 Shared Function PRINT(exp As MalVal) As String
20 return printer._pr_str(exp, TRUE)
21 End Function
22
23 ' repl
24 Shared Function REP(str As String) As String
25 Return PRINT(EVAL(READ(str), ""))
26 End Function
27
28 Shared Function Main As Integer
29 Dim args As String() = Environment.GetCommandLineArgs()
30
31 If args.Length > 1 AndAlso args(1) = "--raw" Then
32 Mal.readline.SetMode(Mal.readline.Modes.Raw)
33 End If
34
35 ' repl loop
36 Dim line As String
37 Do
38 Try
39 line = Mal.readline.Readline("user> ")
40 If line is Nothing Then
41 Exit Do
42 End If
43 If line = "" Then
44 Continue Do
45 End If
46 Catch e As IOException
47 Console.WriteLine("IOException: " & e.Message)
48 End Try
49 Try
50 Console.WriteLine(REP(line))
51 Catch e as Exception
52 Console.WriteLine("Error: " & e.Message)
53 Console.WriteLine(e.StackTrace)
54 Continue Do
55 End Try
56 Loop While True
57 End function
58 End Class
59 End Namespace