about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-09-22 00:16:21 -0700
committerKartik Agaram <vc@akkartik.com>2018-09-22 00:16:21 -0700
commit08c2f2a5ce0a55c1b33314309ab857d305a0e58b (patch)
treee50605d4c4a11599c8abbc13e58e52da44f1677b
parent3f8597bc3d44ab26536b080ae00e3b66202137d6 (diff)
downloadmu-08c2f2a5ce0a55c1b33314309ab857d305a0e58b.tar.gz
4587
-rw-r--r--subx/apps/factorial.k221
-rw-r--r--subx/examples/ex3.k220
-rw-r--r--subx/examples/ex4.k217
-rw-r--r--subx/examples/ex5.k212
-rw-r--r--subx/examples/ex6.k213
-rw-r--r--subx/examples/ex7.k224
-rw-r--r--subx/examples/ex8.k241
7 files changed, 0 insertions, 148 deletions
diff --git a/subx/apps/factorial.k2 b/subx/apps/factorial.k2
deleted file mode 100644
index 82c44352..00000000
--- a/subx/apps/factorial.k2
+++ /dev/null
@@ -1,21 +0,0 @@
-fn factorial n : int -> result/EAX : int [
-  result/EAX <- copy 1
-  {
-    compare n, 1
-    break-if <=
-    var tmp/EBX : int
-    tmp/EBX <- copy n
-    tmp/EBX <- subtract 1
-    var tmp2/EAX : int
-    tmp2/EAX <- call factorial, tmp/EBX
-    result/EAX <- multiply tmp2/EAX, n
-  }
-  return result/EAX
-]
-
-data structures:
-
-add entry for "factorial" into the Types table, with value (fn int -> int)
-add entry for "factorial" into the address table, with value next available address
-add entry for "factorial" into the size table, with value size of "0b 0a bb ..."
-increase next available address by size of "factorial"
diff --git a/subx/examples/ex3.k2 b/subx/examples/ex3.k2
deleted file mode 100644
index aa17ac7b..00000000
--- a/subx/examples/ex3.k2
+++ /dev/null
@@ -1,20 +0,0 @@
-fn main [
-  var result/EBX : int
-  result/EBX <- copy 0
-  var counter/ECX : int
-  counter/ECX <- copy 1
-  {
-    compare counter/ECX, 10
-    break-if >
-    result/EBX <- add counter/ECX
-    counter/ECX <- add 1
-    loop
-  }
-  call exit, 1
-]
-
-fn exit x : int [
-  code/EBX <- copy x
-  code/EAX <- copy 1/exit
-  syscall
-]
diff --git a/subx/examples/ex4.k2 b/subx/examples/ex4.k2
deleted file mode 100644
index ad968eaf..00000000
--- a/subx/examples/ex4.k2
+++ /dev/null
@@ -1,17 +0,0 @@
-# variables are always references
-#   read their address with their names: x (can't write to their address)
-#   read/write their contents with a lookup: *x
-var x : char
-
-fn main [
-  call read 0/stdin, x, 1/size  # watch out; reading a global may not be possible in all instructions
-                                # but the address is more easily obtained
-  result/EAX <- call write 1/stdout, x, 1/size
-  call exit, result/EAX
-]
-
-fn exit x : int [
-  code/EBX <- copy x
-  code/EAX <- copy 1/exit
-  syscall
-]
diff --git a/subx/examples/ex5.k2 b/subx/examples/ex5.k2
deleted file mode 100644
index 79920614..00000000
--- a/subx/examples/ex5.k2
+++ /dev/null
@@ -1,12 +0,0 @@
-fn main [
-  var x : char
-  call read 0/stdin, x, 1/size
-  result/EBX <- call write 1/stdout, x, 1/size
-  call exit-EBX
-]
-
-# like exit, but assumes the code is already in EBX
-fn exit-EBX [
-  code/EAX <- copy 1/exit
-  syscall
-]
diff --git a/subx/examples/ex6.k2 b/subx/examples/ex6.k2
deleted file mode 100644
index d9b54dd4..00000000
--- a/subx/examples/ex6.k2
+++ /dev/null
@@ -1,13 +0,0 @@
-var size : int = 14
-var x : (array character) = "hello, world!"
-
-fn main [
-  call write 1/stdout, x, size
-  call exit, 0
-]
-
-fn exit x : int [
-  code/EBX <- copy x
-  code/EAX <- copy 1/exit
-  syscall
-]
diff --git a/subx/examples/ex7.k2 b/subx/examples/ex7.k2
deleted file mode 100644
index 515c5c12..00000000
--- a/subx/examples/ex7.k2
+++ /dev/null
@@ -1,24 +0,0 @@
-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
-]
-
-# like exit, but assumes the code is already in EBX
-fn exit-EBX [
-  code/EAX <- copy 1/exit
-  syscall
-]
diff --git a/subx/examples/ex8.k2 b/subx/examples/ex8.k2
deleted file mode 100644
index f6c359f7..00000000
--- a/subx/examples/ex8.k2
+++ /dev/null
@@ -1,41 +0,0 @@
-fn main argc : int, argv : (array (ref array char)) -> [
-  var tmp : (index char)
-  tmp <- index 1, %size(ref array char)
-  var tmp2 : (address (ref array char))
-  tmp2 <- advance argv, tmp
-  var s/EBX : (ref array char)
-  s/EBX <- copy *tmp2
-  var result/EAX : int
-  result/EAX <- ascii_length s/EBX
-  call exit, result/EAX
-]
-
-# must 
-fn ascii_length s : (ref array char) -> result : int [
-  var result/EBX : int
-  result/EBX <- copy 0
-  {
-    var tmp0/EDI : (offset char)
-    tmp0/EDI <- index result/EBX, %size(char)
-    var tmp/EDX : (address char)
-    tmp/EDX <- advance *s, tmp0/EDI
-      => compare (ESP+4), *(ESP+8)  ; '*' from compiler2
-         jump-unless-equal panic
-         EDX <- add ESP, 8
-         EDX <- copy *EDX
-         EDX <- add EDX, 4
-         EDX <- 8d/lea EDX + result
-    var c/ECX : char
-    c/ECX <- copy *tmp
-    compare c/ECX, 0
-    break-if-equal
-    loop
-  }
-  return result/EBX
-]
-
-fn exit x : int [
-  code/EBX <- copy x
-  code/EAX <- copy 1/exit
-  syscall
-]