1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
;; Wasm_of_ocaml runtime support
;; http://www.ocsigen.org/js_of_ocaml/
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU Lesser General Public License as published by
;; the Free Software Foundation, with linking exception;
;; either version 2.1 of the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
(module
(import "bindings" "on_windows" (global $on_windows i32))
(import "bindings" "getcwd" (func $getcwd (result anyref)))
(import "bindings" "chdir" (func $chdir (param anyref)))
(import "bindings" "mkdir" (func $mkdir (param anyref) (param i32)))
(import "bindings" "rmdir" (func $rmdir (param anyref)))
(import "bindings" "unlink" (func $unlink (param anyref)))
(import "bindings" "tmpdir" (func $tmpdir (result anyref)))
(import "bindings" "read_dir"
(func $read_dir (param anyref) (result (ref extern))))
(import "bindings" "file_exists"
(func $file_exists (param anyref) (result (ref eq))))
(import "bindings" "is_directory"
(func $is_directory (param anyref) (result (ref eq))))
(import "bindings" "is_file"
(func $is_file (param anyref) (result (ref eq))))
(import "bindings" "rename" (func $rename (param anyref) (param anyref)))
(import "jslib" "wrap" (func $wrap (param anyref) (result (ref eq))))
(import "jslib" "unwrap" (func $unwrap (param (ref eq)) (result anyref)))
(import "jslib" "caml_string_of_jsstring"
(func $caml_string_of_jsstring (param (ref eq)) (result (ref eq))))
(import "jslib" "caml_jsstring_of_string"
(func $caml_jsstring_of_string (param (ref eq)) (result (ref eq))))
(import "jslib" "caml_js_to_string_array"
(func $caml_js_to_string_array (param $a (ref extern)) (result (ref eq))))
(import "fail" "caml_raise_sys_error"
(func $caml_raise_sys_error (param (ref eq))))
(import "fail" "javascript_exception"
(tag $javascript_exception (param externref)))
(import "sys" "caml_handle_sys_error"
(func $caml_handle_sys_error (param externref)))
(import "string" "caml_string_concat"
(func $caml_string_concat (param (ref eq) (ref eq)) (result (ref eq))))
(type $bytes (array (mut i8)))
(func (export "caml_sys_getcwd")
(param (ref eq)) (result (ref eq))
(try (result (ref eq))
(do
(call $caml_string_of_jsstring (call $wrap (call $getcwd))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))
(ref.i31 (i32.const 0)))))
(func (export "caml_sys_chdir")
(param $name (ref eq)) (result (ref eq))
(try
(do
(call $chdir
(call $unwrap (call $caml_jsstring_of_string (local.get $name)))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))))
(ref.i31 (i32.const 0)))
(func (export "caml_sys_mkdir")
(param $name (ref eq)) (param $perm (ref eq)) (result (ref eq))
(try
(do
(call $mkdir
(call $unwrap (call $caml_jsstring_of_string (local.get $name)))
(i31.get_u (ref.cast (ref i31) (local.get $perm)))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))))
(ref.i31 (i32.const 0)))
(func (export "caml_sys_read_directory")
(param $name (ref eq)) (result (ref eq))
(try
(do
(return
(call $caml_js_to_string_array
(call $read_dir
(call $unwrap
(call $caml_jsstring_of_string (local.get $name)))))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))
(return (ref.i31 (i32.const 0))))))
(func (export "caml_sys_rmdir")
(param $name (ref eq)) (result (ref eq))
(try
(do
(call $rmdir
(call $unwrap (call $caml_jsstring_of_string (local.get $name)))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))))
(ref.i31 (i32.const 0)))
(func (export "caml_sys_remove")
(param $name (ref eq)) (result (ref eq))
(try
(do
(call $unlink
(call $unwrap (call $caml_jsstring_of_string (local.get $name)))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))))
(ref.i31 (i32.const 0)))
(func (export "caml_sys_rename")
(param $o (ref eq)) (param $n (ref eq)) (result (ref eq))
(try
(do
(call $rename
(call $unwrap (call $caml_jsstring_of_string (local.get $o)))
(call $unwrap (call $caml_jsstring_of_string (local.get $n)))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))))
(ref.i31 (i32.const 0)))
(func (export "caml_sys_file_exists")
(param $name (ref eq)) (result (ref eq))
(return_call $file_exists
(call $unwrap (call $caml_jsstring_of_string (local.get $name)))))
(@string $no_such_file ": No such file or directory")
(func $caml_raise_no_such_file (param $name (ref eq))
(call $caml_raise_sys_error
(call $caml_string_concat (local.get $name)
(global.get $no_such_file))))
(func (export "caml_read_file_content")
(param (ref eq)) (result (ref eq))
(call $caml_raise_no_such_file (local.get 0))
(ref.i31 (i32.const 0)))
(func (export "caml_create_file")
(param (ref eq)) (param (ref eq)) (result (ref eq))
(call $caml_raise_no_such_file (local.get 0))
(ref.i31 (i32.const 0)))
(func (export "caml_fs_init") (result (ref eq))
(ref.i31 (i32.const 0)))
(func (export "caml_sys_is_directory")
(param $name (ref eq)) (result (ref eq))
(try
(do
(return
(call $is_directory
(call $unwrap
(call $caml_jsstring_of_string (local.get $name))))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))
(return (ref.i31 (i32.const 0))))))
(func (export "caml_sys_is_regular_file")
(param $name (ref eq)) (result (ref eq))
(try
(do
(return
(call $is_file
(call $unwrap
(call $caml_jsstring_of_string (local.get $name))))))
(catch $javascript_exception
(call $caml_handle_sys_error (pop externref))
(return (ref.i31 (i32.const 0))))))
(func (export "caml_sys_temp_dir_name") (param (ref eq)) (result (ref eq))
(if (global.get $on_windows)
(then
(return_call $caml_string_of_jsstring (call $wrap (call $tmpdir)))))
(@string ""))
(func (export "caml_mount_autoload")
(param (ref eq) (ref eq)) (result (ref eq))
(ref.i31 (i32.const 0)))
)
|