about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-11 21:46:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-06-11 21:46:59 -0700
commit952fb9a677de3f59aec09df3377858525ca03705 (patch)
treee31b5514df856cd2318236085fb579b2ff09a194
parent0dc4f9c62bf26b373284e7d27aa41c500c8bd16a (diff)
downloadmu-952fb9a677de3f59aec09df3377858525ca03705.tar.gz
car/cdr of nil is now nil
-rw-r--r--shell/primitives.mu20
1 files changed, 18 insertions, 2 deletions
diff --git a/shell/primitives.mu b/shell/primitives.mu
index a8f22141..59fb86cf 100644
--- a/shell/primitives.mu
+++ b/shell/primitives.mu
@@ -774,7 +774,7 @@ fn apply-car _args-ah: (addr handle cell), out: (addr handle cell), trace: (addr
     return
   }
   # args->left
-  var first-ah/eax: (addr handle cell) <- get args, left
+  var first-ah/edx: (addr handle cell) <- get args, left
   var first/eax: (addr cell) <- lookup *first-ah
   var first-type/ecx: (addr int) <- get first, type
   compare *first-type, 0/pair
@@ -783,6 +783,14 @@ fn apply-car _args-ah: (addr handle cell), out: (addr handle cell), trace: (addr
     error trace, "arg for car is not a pair"
     return
   }
+  # nil? return nil
+  {
+    var nil?/eax: boolean <- nil? first
+    compare nil?, 0/false
+    break-if-=
+    copy-object first-ah, out
+    return
+  }
   # car
   var result/eax: (addr handle cell) <- get first, left
   copy-object result, out
@@ -802,7 +810,7 @@ fn apply-cdr _args-ah: (addr handle cell), out: (addr handle cell), trace: (addr
     return
   }
   # args->left
-  var first-ah/eax: (addr handle cell) <- get args, left
+  var first-ah/edx: (addr handle cell) <- get args, left
   var first/eax: (addr cell) <- lookup *first-ah
   var first-type/ecx: (addr int) <- get first, type
   compare *first-type, 0/pair
@@ -811,6 +819,14 @@ fn apply-cdr _args-ah: (addr handle cell), out: (addr handle cell), trace: (addr
     error trace, "arg for cdr is not a pair"
     return
   }
+  # nil? return nil
+  {
+    var nil?/eax: boolean <- nil? first
+    compare nil?, 0/false
+    break-if-=
+    copy-object first-ah, out
+    return
+  }
   # cdr
   var result/eax: (addr handle cell) <- get first, right
   copy-object result, out