userland/src/lib: make this look pretty

This commit is contained in:
Cadey Ratio 2018-06-18 02:42:49 +00:00
parent eedf0b024d
commit d582c3b14b
1 changed files with 29 additions and 29 deletions

View File

@ -17,67 +17,67 @@
;; functions ;; functions
(func $openFile (result i32) (func $openFile (result i32)
;; open stdout ;; open stdout
(i32.const 200) (call $open
(i32.const 42) (i32.const 200)
(call $open)) (i32.const 42)))
(func $writeHelloWorld (param $fd i32) (func $writeHelloWorld (param $fd i32)
;; write hello world ;; write hello world
(get_local $fd) (call $write
(i32.const 230) (get_local $fd)
(i32.const 14) (i32.const 230)
(call $write) (i32.const 14))
(drop)) (drop))
(func $readHello (param $fd i32) (func $readHello (param $fd i32)
;; read hello world ;; read hello world
(get_local $fd) (call $read
(i32.const 255) (get_local $fd)
(i32.const 14) (i32.const 255)
(call $read) (i32.const 14))
(drop)) (drop))
(func $removeFile (func $removeFile
(i32.const 200) (call $unlink
(call $unlink) (i32.const 200))
(drop)) (drop))
(func $main (result i32) (func $main (result i32)
(local $fd i32) (local $fd i32)
;; set $fd to the file descriptor ;; set $fd to the file descriptor
(call $openFile) (set_local $fd
(set_local $fd) (call $openFile))
(get_local $fd) (call $writeHelloWorld
(call $writeHelloWorld) (get_local $fd))
;; close file ;; close file
(get_local $fd) (call $close
(call $close) (get_local $fd))
;; set $fd to the new file descriptor ;; set $fd to the new file descriptor
(call $openFile) (set_local $fd
(set_local $fd) (call $openFile))
;; read Hello, World ;; read Hello, World
(get_local $fd) (call $readHello
(call $readHello) (get_local $fd))
;; istty ;; istty
(get_local $fd) (call $istty
(call $istty) (get_local $fd))
(drop) (drop)
;; close file again ;; close file again
(get_local $fd) (call $close
(call $close) (get_local $fd))
;; unlink filename ;; unlink filename
(call $removeFile) (call $removeFile)
;; return 0 ;; return 0
(i32.const 0) (set_local $fd
(set_local $fd) (i32.const 0))
(drop)) (drop))
(export "main" (func $main))) (export "main" (func $main)))