about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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