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
5 changes: 3 additions & 2 deletions PRIMITIVES.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ added to them too.
* Integer square root, which rounds down.
* `newline`
* Print a newline.
* `now`
* Get the milliseconds past the epoch.
* `not`
* If the supplied value is `nil` return 1, otherwise return `nil`.
* `nth`
Expand Down Expand Up @@ -186,6 +184,7 @@ added to them too.
* Return the number of objects stored within our heap.



## Standard Library

The standard library consists of routines, and helpers, which are written in 100% `slisp` itself.
Expand Down Expand Up @@ -279,6 +278,8 @@ The implementation of these primitives can be found in the file [stdlib.slisp](s
* Return the list of natural numbers 1 to N.
* `neg?`
* Return true if the number is negative.
* `now`
* Get the milliseconds past the epoch.
* `odd?`
* Return 1 if the given number is odd, nil otherwise.
* `one?`
Expand Down
28 changes: 0 additions & 28 deletions compiler/template.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@

SYS_write equ 1
SYS_exit equ 60
SYS_clock_gettime equ 228
SYS_prlimit64 equ 302

;; stack size fetch
Expand Down Expand Up @@ -1885,33 +1884,6 @@ FUNC fn_sys_not



;; Get milliseconds since epoch
FUNC fn_sys_now
sub rsp, 16 ; Reserve space for struct timespec

mov eax, SYS_clock_gettime
mov edi, 0 ; CLOCK_REALTIME
mov rsi, rsp
syscall

; Convert to milliseconds:
; ms = tv_sec * 1000 + tv_nsec / 1,000,000
mov rax, [rsp] ; tv_sec
imul rax, rax, 1000
mov r8, rax ; Save seconds in ms
mov rax, [rsp+8] ; tv_nsec
xor edx, edx
mov ecx, 1000000
div rcx ; RAX = tv_nsec / 1,000,000
add rax, r8 ; Total milliseconds
add rsp, 16 ; Free stack space

; RAX now contains milliseconds since the Unix epoch
TAG_INTEGER_REG rax
ret



;; Get the Nth item from the list
FUNC fn_sys_nth
mov rbx,rdi ; type-check arg1: list
Expand Down
1 change: 0 additions & 1 deletion inception.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@
(register-builtin "sys_multiply" (lambda (args) (sys_multiply (car args) (cadr args))))
(register-builtin "sys_newline" (lambda (args) (sys_newline)))
(register-builtin "sys_not" (lambda (args) (sys_not (car args))))
(register-builtin "sys_now" (lambda (args) (sys_now)))
(register-builtin "sys_nth!" (lambda (args) (sys_nth! (car args) (cadr args) (caddr args))))
(register-builtin "sys_nth" (lambda (args) (sys_nth (car args) (cadr args))))
(register-builtin "sys_or" (lambda (args) (sys_or (car args) (cadr args))))
Expand Down
26 changes: 13 additions & 13 deletions stdlib.slisp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ reap orphaned memory."
"Return true when given NIL, otherwise return NIL"
(sys_not x))

(defun now ()
"Return the number of milliseconds since the Unix EPOCH."
(sys_now))

(defun isqrt(x)
"Perform an integer square root of the given number."
(sys_isqrt x))
Expand Down Expand Up @@ -162,10 +158,6 @@ reap orphaned memory."
"Load all packages which are embedded in our run-time."
(map (lambda (p) (require p)) (packages)))

(defun rmdir (str)
"Remove the given directory."
(sys_rmdir str))

(defun split (str c)
"Split a string on the given character.

Expand Down Expand Up @@ -248,11 +240,6 @@ The first argument is the number of the function to call, after that the argumen
"Invoke a kernel system-call with six arguments."
(sys_syscall a b c d e f))

(defun unlink (str)
"Delete the given file from the filesystem.

Use (rmdir) to remove directories instead of files."
(sys_unlink str))

;;; 1. Compatibility

Expand Down Expand Up @@ -647,6 +634,9 @@ This returns a list of the form (TYPE SIZE MODE)."
(defconst SYS_unlink 87)

(defun unlink (path)
"Delete the given file from the filesystem.

Use (rmdir) to remove directories instead of files."
(syscall SYS_unlink path))


Expand Down Expand Up @@ -1187,6 +1177,16 @@ Uses (environment) to get all environmental variables, and filters."
(getenv-loop name (cdr xs))))
nil))

(defconst SYS_clock_gettime 228)

(defun now ()
"Return the number of milliseconds since the Unix EPOCH."
(let ((buffer (alloc 16)))
(syscall SYS_clock_gettime 0 buffer)
(let ((tv_sec (u64 buffer 0))
(tv_nsec (u64 buffer 8)))
(+ (* tv_sec 1000) (/ tv_nsec 1000000)))))


(defun putc (c)
"Write the single specified character to STDOUT."
Expand Down
Loading