load-file: accept empty file or final comment, return nil
[jackhill/mal.git] / wasm / step0_repl.wam
1 (module $step0_repl
2
3 ;; READ
4 (func $READ (param $str i32) (result i32)
5 $str
6 )
7
8 (func $EVAL (param $ast i32) (param $env i32) (result i32)
9 $ast
10 )
11
12 ;; PRINT
13 (func $PRINT (param $ast i32) (result i32)
14 $ast
15 )
16
17 ;; REPL
18 (func $rep (param $line i32) (result i32)
19 ($PRINT ($EVAL ($READ $line) 0))
20 )
21
22 (func $main (param $argc i32 $argv i32) (result i32)
23 ;; Constant location/value definitions
24 (LET $line (STATIC_ARRAY 201))
25
26 ;; DEBUG
27 ;;($printf_1 "memoryBase: 0x%x\n" (global.get $memoryBase))
28
29 ;; Start REPL
30 (block $repl_done
31 (loop $repl_loop
32 (br_if $repl_done (i32.eqz ($readline "user> " $line)))
33 (br_if $repl_loop (i32.eq (i32.load8_u $line) 0))
34 ($printf_1 "%s\n" ($rep $line))
35 (br $repl_loop)
36 )
37 )
38
39 ($print "\n")
40 0
41 )
42
43 ;; init_memory is provided by mem.wam in later steps but we just
44 ;; printf in step0 so provide init_memory that just calls that
45 (func $init_memory
46 ($init_printf_mem)
47 )
48 )
49