about summary refs log tree commit diff stats
path: root/src/command/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/command/commands.c')
-rw-r--r--src/command/commands.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 71ab2ca7..6c3f6874 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -79,7 +79,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
       
# example showing file syscalls
#
# Create a file, open it for writing, write a character to it, close it, open
# it for reading, read a character from it, close it, delete it, and return
# the character read.

var stream : int = 0
var a : char = 97
var b : char = 0
var filename : (array char) = ".foo"

fn main [
  call create, filename
  *stream <- call open, filename, 1/wronly
  call write, *stream, a, 1
  call close, *stream
  stream <- call open, filename, 0/rdonly
  call read, *stream, b, 1
  call close, *stream
  call unlink, filename
  var result/EBX : char
  result/EBX <- copy b  # TODO: copy char to int?
  call exit-EBX
]

fn read fd : int, x : (address array byte), size : int [
  EBX <- copy fd
  ECX <- copy x
  EDX <- copy size
  EAX <- copy 3/read
  syscall
]

fn write fd : int, x : (address array byte), size : int [
  EBX <- copy fd
  ECX <- copy x
  EDX <- copy size
  EAX <- copy 4/write
  syscall
]

fn open name : (address array byte) [
  EBX <- copy name
  EAX <- copy 5/open
  syscall
]

fn close name : (address array byte) [
  EBX <- copy name
  EAX <- copy 6/close
  syscall
]

fn unlink name : (address array byte) [
  EBX <- copy name
  EAX <- copy 10/unlink
  syscall
]

# like exit, but assumes the code is already in EBX
fn exit-EBX [
  code/EAX <- copy 1/exit
  syscall
]