1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-19 17:47:53 +03:00
mal/impls/wasm/platform_direct.wam
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

57 lines
1.6 KiB
Plaintext

(module $platform_direct
(import "env" "memory" (memory 256))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "exit" (func $lib_exit (param i32)))
(import "env" "printline" (func $lib_printline (param i32) (result i32)))
(import "env" "readline" (func $lib_readline (param i32 i32 i32) (result i32)))
(import "env" "read_file" (func $lib_read_file (param i32 i32) (result i32)))
(import "env" "get_time_ms" (func $lib_get_time_ms (result i32)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(func $fatal (param $code i32 $msg i32)
($print $msg)
($lib_exit $code)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(func $print (param $addr i32)
(drop ($lib_printline $addr))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(func $readline (param $prompt i32 $buf i32) (result i32)
;; TODO: don't hardcode count to 200
($lib_readline $prompt $buf 200)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(func $read_file (param $path i32 $buf i32) (result i32)
(LET $size ($lib_read_file $path $buf))
;; Add null to string
(i32.store8 (i32.add $buf $size) 0)
(i32.add $size 1)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(func $get_time_ms (result i32)
($lib_get_time_ms)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(func $entry (param $argc i32 $argv i32)
($init_memory)
($lib_exit ($main $argc $argv))
)
(export "_main" (func $entry))
)