Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PRIMITIVES.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Note that functions have their names mangled a little bit ("-" is converted to "

* Type checking functions:
* `char?`, `cons?`, `float?`, `int?`, `lambda?`, `nil?`, and `str?`.
* The `numeric?` primitive will return true for ints, floats, and characters.
* mathematical operations `*`, `+`, `-`, and `/`.
* These work against integers, floating point numbers, or mixed operands.
* (Integer) comparison operations
Expand Down
2 changes: 2 additions & 0 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ func (c *Compiler) asmName(name string) string {
return "lambdap"
case "nil?":
return "nilp"
case "numeric?":
return "numericp"
case "str?":
return "strp"
}
Expand Down
17 changes: 17 additions & 0 deletions compiler/template.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ strp:
jmp is_type


;; numeric?
numericp:
mov rax, rdi
GET_TAG_BITS rax
call is_numeric
cmp rax, 0
jnz .true
.nil:
xor rax, rax
TAG_NIL_REG rax
ret
.true:
mov rax, 1
TAG_INTEGER_REG rax
ret


;; Internal helper
is_numeric:
cmp rax,TAG_ID_INTEGER
Expand Down
8 changes: 8 additions & 0 deletions test/numeric.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(defun main ()
(println (numeric? 3))
(println (numeric? 3.0))
(println (numeric? #\a))
(println (numeric? (lambda (x) x)))
(println (numeric? nil))
(println (numeric? (list 3 4 )))
(println (numeric? "string")))
7 changes: 7 additions & 0 deletions test/numeric.test.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1
1
1
<nil>
<nil>
<nil>
<nil>
Loading