Eigenstate: myrddin-dev mailing list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/4] Make timespec/timeval struct members signed to simplify arithmetic.


---
 lib/std/syswrap+posixy.myr                    |  2 +-
 lib/std/syswrap-ss+freebsd.myr                |  4 ++--
 lib/std/syswrap-ss+linux.myr                  |  4 ++--
 lib/std/syswrap-ss+netbsd.myr                 |  4 ++--
 lib/std/syswrap-ss+openbsd.myr                |  4 ++--
 lib/std/syswrap-ss+osx.myr                    |  4 ++--
 lib/sys/sys+freebsd-x64.myr                   |  8 +++----
 lib/sys/sys+linux-x64.myr                     |  8 +++----
 lib/sys/sys+netbsd-x64.myr                    |  8 +++----
 lib/sys/sys+openbsd-x64.myr                   | 10 ++++----
 lib/sys/sys+openbsd:6.1-x64.myr               | 10 ++++----
 lib/sys/sys+openbsd:6.2-x64.myr               | 10 ++++----
 lib/sys/sys+openbsd:6.3-x64.myr               | 10 ++++----
 lib/sys/sys+osx-x64.myr                       | 23 ++++++++++++-------
 .../syscall-gen/specials+openbsd:6.1-x64.frag |  2 +-
 .../syscall-gen/specials+openbsd:6.2-x64.frag |  2 +-
 .../syscall-gen/specials+openbsd:6.3-x64.frag |  2 +-
 support/syscall-gen/types+freebsd-x64.frag    |  8 +++----
 support/syscall-gen/types+linux-x64.frag      |  8 +++----
 .../syscall-gen/types+openbsd:6.1-x64.frag    |  8 +++----
 .../syscall-gen/types+openbsd:6.2-x64.frag    |  8 +++----
 .../syscall-gen/types+openbsd:6.3-x64.frag    |  8 +++----
 22 files changed, 81 insertions(+), 74 deletions(-)

diff --git a/lib/std/syswrap+posixy.myr b/lib/std/syswrap+posixy.myr
index b3b9baa8..41c6e89a 100644
--- a/lib/std/syswrap+posixy.myr
+++ b/lib/std/syswrap+posixy.myr
@@ -139,7 +139,7 @@ const curtime = {
 
 	if sys.clock_gettime(`sys.Clockrealtime, &tm) == 0
 		sec = tm.sec
-		nsec = (tm.nsec : uint64)
+		nsec = tm.nsec
 		-> ((sec*1_000_000 + nsec/1000) : time)
 	else
 		-> -1
diff --git a/lib/std/syswrap-ss+freebsd.myr b/lib/std/syswrap-ss+freebsd.myr
index f445d176..0cad82a5 100644
--- a/lib/std/syswrap-ss+freebsd.myr
+++ b/lib/std/syswrap-ss+freebsd.myr
@@ -16,8 +16,8 @@ const nanosleep	= {nsecs
 	var req, rem
 	var s, ns
 
-	s = nsecs / 1_000_000_000
-	ns = nsecs % 1_000_000_000
+	s = (nsecs / 1_000_000_000 : int64)
+	ns = (nsecs % 1_000_000_000 : int64)
 	req = [.sec = s, .nsec = ns]
 
 	-> (sys.nanosleep(&req, &rem) : errno)
diff --git a/lib/std/syswrap-ss+linux.myr b/lib/std/syswrap-ss+linux.myr
index c4b77951..760a7db0 100644
--- a/lib/std/syswrap-ss+linux.myr
+++ b/lib/std/syswrap-ss+linux.myr
@@ -13,8 +13,8 @@ const nanosleep	= {nsecs
 	var req, rem
 	var s, ns
 
-	s = nsecs / 1_000_000_000
-	ns = nsecs % 1_000_000_000
+	s = (nsecs / 1_000_000_000 : int64)
+	ns = (nsecs % 1_000_000_000 : int64)
 	req = [.sec = s, .nsec = ns]
 
 	-> (sys.nanosleep(&req, &rem) : errno)
diff --git a/lib/std/syswrap-ss+netbsd.myr b/lib/std/syswrap-ss+netbsd.myr
index 42605ab5..0f4ed65d 100644
--- a/lib/std/syswrap-ss+netbsd.myr
+++ b/lib/std/syswrap-ss+netbsd.myr
@@ -22,8 +22,8 @@ const nanosleep	= {nsecs
 	var req, rem
 	var s, ns
 
-	s = nsecs / 1_000_000_000
-	ns = nsecs % 1_000_000_000
+	s = (nsecs / 1_000_000_000 : int64)
+	ns = (nsecs % 1_000_000_000 : int64)
 	req = [.sec = s, .nsec = ns]
 
 	-> (sys.nanosleep(&req, &rem) : errno)
diff --git a/lib/std/syswrap-ss+openbsd.myr b/lib/std/syswrap-ss+openbsd.myr
index 42605ab5..0f4ed65d 100644
--- a/lib/std/syswrap-ss+openbsd.myr
+++ b/lib/std/syswrap-ss+openbsd.myr
@@ -22,8 +22,8 @@ const nanosleep	= {nsecs
 	var req, rem
 	var s, ns
 
-	s = nsecs / 1_000_000_000
-	ns = nsecs % 1_000_000_000
+	s = (nsecs / 1_000_000_000 : int64)
+	ns = (nsecs % 1_000_000_000 : int64)
 	req = [.sec = s, .nsec = ns]
 
 	-> (sys.nanosleep(&req, &rem) : errno)
diff --git a/lib/std/syswrap-ss+osx.myr b/lib/std/syswrap-ss+osx.myr
index a7739495..53a1db1e 100644
--- a/lib/std/syswrap-ss+osx.myr
+++ b/lib/std/syswrap-ss+osx.myr
@@ -17,8 +17,8 @@ extern const put	: (fmt : byte[:], args : ... -> int64)
 const nanosleep	= {nsecs
 	var s, us
 
-	s = nsecs / 1_000_000_000
-	us = (nsecs % 1_000_000_000 / 1000 : uint32)
+	s = (nsecs / 1_000_000_000 : int64)
+	us = (nsecs % 1_000_000_000 / 1000 : int32)
 	-> (sys.select( \
 		0, \
 		(0 : sys.fdset#), \
diff --git a/lib/sys/sys+freebsd-x64.myr b/lib/sys/sys+freebsd-x64.myr
index a140f0af..e1cfb692 100644
--- a/lib/sys/sys+freebsd-x64.myr
+++ b/lib/sys/sys+freebsd-x64.myr
@@ -262,13 +262,13 @@ pkg sys =
 	;;
 	
 	type timespec = struct
-		sec	: uint64
-		nsec	: uint64 
+		sec	: int64
+		nsec	: int64
 	;;
 	
 	type timeval = struct
-		sec	: uint64
-		usec	: uint64
+		sec	: int64
+		usec	: int64
 	;;
 	
 	type itimerval = struct
diff --git a/lib/sys/sys+linux-x64.myr b/lib/sys/sys+linux-x64.myr
index 575143d6..1cebb123 100644
--- a/lib/sys/sys+linux-x64.myr
+++ b/lib/sys/sys+linux-x64.myr
@@ -102,13 +102,13 @@ pkg sys =
 	;;
 	
 	type timespec = struct
-		sec	: uint64
-		nsec	: uint64
+		sec	: int64
+		nsec	: int64
 	;;
 	
 	type timeval = struct
-		sec	: uint64
-		usec	: uint64
+		sec	: int64
+		usec	: int64
 	;;
 	
 	type timex = struct
diff --git a/lib/sys/sys+netbsd-x64.myr b/lib/sys/sys+netbsd-x64.myr
index f380afe9..8e22c0b7 100644
--- a/lib/sys/sys+netbsd-x64.myr
+++ b/lib/sys/sys+netbsd-x64.myr
@@ -50,13 +50,13 @@ pkg sys =
 	;;
 
 	type timespec = struct
-		sec	: uint64
-		nsec	: uint64 
+		sec	: int64
+		nsec	: int64
 	;;
 
 	type timeval = struct
-		sec	: uint64
-		usec	: uint64
+		sec	: int64
+		usec	: int64
 	;;
 
 	type rusage = struct
diff --git a/lib/sys/sys+openbsd-x64.myr b/lib/sys/sys+openbsd-x64.myr
index 454567a4..a2601344 100644
--- a/lib/sys/sys+openbsd-x64.myr
+++ b/lib/sys/sys+openbsd-x64.myr
@@ -35,13 +35,13 @@ pkg sys =
 	;;
 
 	type timespec = struct
-		sec	: uint64
-		nsec	: uint64 
+		sec	: int64
+		nsec	: int64
 	;;
 
 	type timeval = struct
-		sec	: uint64
-		usec	: uint64
+		sec	: int64
+		usec	: int64
 	;;
 
 
@@ -751,7 +751,7 @@ const clock_settime = {clk, ts;	-> (syscall(Sysclock_settime, clockid(clk), a(ts
 
 const sleep = {time
 	var req, rem
-	req = [.sec = time, .nsec = 0]
+	req = [.sec = (time : int64), .nsec = 0]
 	-> nanosleep(&req, &rem)
 }
 
diff --git a/lib/sys/sys+openbsd:6.1-x64.myr b/lib/sys/sys+openbsd:6.1-x64.myr
index ced1a80e..93143945 100644
--- a/lib/sys/sys+openbsd:6.1-x64.myr
+++ b/lib/sys/sys+openbsd:6.1-x64.myr
@@ -44,13 +44,13 @@ pkg sys =
 	;;
 	
 	type timespec = struct
-		sec	: uint64
-		nsec	: uint64 
+		sec	: int64
+		nsec	: int64
 	;;
 	
 	type timeval = struct
-		sec	: uint64
-		usec	: uint64
+		sec	: int64
+		usec	: int64
 	;;
 	
 	
@@ -1168,7 +1168,7 @@ pkg sys =
 	
 	const sleep = {time
 		var req, rem
-		req = [.sec = time, .nsec = 0]
+		req = [.sec = (time : int64), .nsec = 0]
 		-> nanosleep(&req, &rem)
 	}
 	
diff --git a/lib/sys/sys+openbsd:6.2-x64.myr b/lib/sys/sys+openbsd:6.2-x64.myr
index 672c844a..598d3817 100644
--- a/lib/sys/sys+openbsd:6.2-x64.myr
+++ b/lib/sys/sys+openbsd:6.2-x64.myr
@@ -49,13 +49,13 @@ pkg sys =
 	;;
 	
 	type timespec = struct
-		sec	: uint64
-		nsec	: uint64 
+		sec	: int64
+		nsec	: int64
 	;;
 	
 	type timeval = struct
-		sec	: uint64
-		usec	: uint64
+		sec	: int64
+		usec	: int64
 	;;
 	
 	type timezone = struct
@@ -1174,7 +1174,7 @@ pkg sys =
 	
 	const sleep = {time
 		var req, rem
-		req = [.sec = time, .nsec = 0]
+		req = [.sec = (time : int64), .nsec = 0]
 		-> nanosleep(&req, &rem)
 	}
 	
diff --git a/lib/sys/sys+openbsd:6.3-x64.myr b/lib/sys/sys+openbsd:6.3-x64.myr
index 82a6b172..d013643e 100644
--- a/lib/sys/sys+openbsd:6.3-x64.myr
+++ b/lib/sys/sys+openbsd:6.3-x64.myr
@@ -55,13 +55,13 @@ pkg sys =
 	;;
 	
 	type timespec = struct
-		sec	: uint64
-		nsec	: uint64 
+		sec	: int64
+		nsec	: int64
 	;;
 	
 	type timeval = struct
-		sec	: uint64
-		usec	: uint64
+		sec	: int64
+		usec	: int64
 	;;
 	
 	type timezone = struct
@@ -1173,7 +1173,7 @@ pkg sys =
 	
 	const sleep = {time
 		var req, rem
-		req = [.sec = time, .nsec = 0]
+		req = [.sec = (time : int64), .nsec = 0]
 		-> nanosleep(&req, &rem)
 	}
 	
diff --git a/lib/sys/sys+osx-x64.myr b/lib/sys/sys+osx-x64.myr
index 1917ffeb..ba97c366 100644
--- a/lib/sys/sys+osx-x64.myr
+++ b/lib/sys/sys+osx-x64.myr
@@ -25,13 +25,13 @@ pkg sys =
 	;;
 
 	type timespec = struct
-		sec	: uint64
-		nsec	: uint32
+		sec	: int64
+		nsec	: int64
 	;;
 
 	type timeval = struct
-		sec	: uint64
-		usec	: uint32
+		sec	: int64
+		usec	: int32
 	;;
 
 	type timezone = struct
@@ -825,7 +825,6 @@ pkg sys =
 	const clock_getres	: (clk : clock, ts : timespec# -> int)
 	const clock_gettime	: (clk : clock, ts : timespec# -> int)
 	const clock_settime	: (clk : clock, ts : timespec# -> int)
-	/* FIXME: HACK HACK HACK -- does nothing */
 	const sleep	: (time : uint64 -> int32)
 
 	/* system information */
@@ -896,7 +895,15 @@ const bsdthread_terminate	= {stk , len , port , sem
 	-> (syscall(Sysbsdthread_terminate, a(stk), a(len), a(port), a(sem)) : int)
 }
 
-const sleep = {time;	-> 0}
+const sleep = {time
+	-> sys.select( \
+		0, \
+		(0 : sys.fdset#), \
+		(0 : sys.fdset#), \
+		(0 : sys.fdset#), \
+		&[.sec = (time : int64), .usec = 0] \
+	)
+}
 
 const execv	= {cmd, args
 	var p, cargs, i
@@ -1021,7 +1028,7 @@ const clock_gettime = {clk, ts
 
 	ret = gettimeofday(&tv, (0 : timezone#))
 	ts.sec = tv.sec
-	ts.nsec = tv.usec * 1000
+	ts.nsec = (tv.usec * 1000 : int64)
 	-> ret
 }
 
@@ -1029,7 +1036,7 @@ const clock_settime = {clk, ts
 	var tv
 
 	tv.sec = ts.sec
-	tv.usec = ts.nsec / 1000
+	tv.usec = (ts.nsec / 1000 : int32)
 	-> settimeofday(&tv, (0 : timezone#))
 }
 
diff --git a/support/syscall-gen/specials+openbsd:6.1-x64.frag b/support/syscall-gen/specials+openbsd:6.1-x64.frag
index 4cc3843e..b326ec16 100644
--- a/support/syscall-gen/specials+openbsd:6.1-x64.frag
+++ b/support/syscall-gen/specials+openbsd:6.1-x64.frag
@@ -190,7 +190,7 @@ const clock_settime = {clk, ts;	-> (syscall(Sysclock_settime, clockid(clk), a(ts
 
 const sleep = {time
 	var req, rem
-	req = [.sec = time, .nsec = 0]
+	req = [.sec = (time : int64), .nsec = 0]
 	-> nanosleep(&req, &rem)
 }
 
diff --git a/support/syscall-gen/specials+openbsd:6.2-x64.frag b/support/syscall-gen/specials+openbsd:6.2-x64.frag
index 4cc3843e..b326ec16 100644
--- a/support/syscall-gen/specials+openbsd:6.2-x64.frag
+++ b/support/syscall-gen/specials+openbsd:6.2-x64.frag
@@ -190,7 +190,7 @@ const clock_settime = {clk, ts;	-> (syscall(Sysclock_settime, clockid(clk), a(ts
 
 const sleep = {time
 	var req, rem
-	req = [.sec = time, .nsec = 0]
+	req = [.sec = (time : int64), .nsec = 0]
 	-> nanosleep(&req, &rem)
 }
 
diff --git a/support/syscall-gen/specials+openbsd:6.3-x64.frag b/support/syscall-gen/specials+openbsd:6.3-x64.frag
index 4cc3843e..b326ec16 100644
--- a/support/syscall-gen/specials+openbsd:6.3-x64.frag
+++ b/support/syscall-gen/specials+openbsd:6.3-x64.frag
@@ -190,7 +190,7 @@ const clock_settime = {clk, ts;	-> (syscall(Sysclock_settime, clockid(clk), a(ts
 
 const sleep = {time
 	var req, rem
-	req = [.sec = time, .nsec = 0]
+	req = [.sec = (time : int64), .nsec = 0]
 	-> nanosleep(&req, &rem)
 }
 
diff --git a/support/syscall-gen/types+freebsd-x64.frag b/support/syscall-gen/types+freebsd-x64.frag
index 62bdaeac..9bae3054 100644
--- a/support/syscall-gen/types+freebsd-x64.frag
+++ b/support/syscall-gen/types+freebsd-x64.frag
@@ -256,13 +256,13 @@ type timezone = struct
 ;;
 
 type timespec = struct
-	sec	: uint64
-	nsec	: uint64 
+	sec	: int64
+	nsec	: int64
 ;;
 
 type timeval = struct
-	sec	: uint64
-	usec	: uint64
+	sec	: int64
+	usec	: int64
 ;;
 
 type itimerval = struct
diff --git a/support/syscall-gen/types+linux-x64.frag b/support/syscall-gen/types+linux-x64.frag
index 235888a0..13d95aaa 100644
--- a/support/syscall-gen/types+linux-x64.frag
+++ b/support/syscall-gen/types+linux-x64.frag
@@ -95,13 +95,13 @@ type sigevent = struct
 ;;
 
 type timespec = struct
-	sec	: uint64
-	nsec	: uint64
+	sec	: int64
+	nsec	: int64
 ;;
 
 type timeval = struct
-	sec	: uint64
-	usec	: uint64
+	sec	: int64
+	usec	: int64
 ;;
 
 type timex = struct
diff --git a/support/syscall-gen/types+openbsd:6.1-x64.frag b/support/syscall-gen/types+openbsd:6.1-x64.frag
index 48b8f5b6..ac7157eb 100644
--- a/support/syscall-gen/types+openbsd:6.1-x64.frag
+++ b/support/syscall-gen/types+openbsd:6.1-x64.frag
@@ -38,13 +38,13 @@ type waitstatus = union
 ;;
 
 type timespec = struct
-	sec	: uint64
-	nsec	: uint64 
+	sec	: int64
+	nsec	: int64
 ;;
 
 type timeval = struct
-	sec	: uint64
-	usec	: uint64
+	sec	: int64
+	usec	: int64
 ;;
 
 type pollfd = struct
diff --git a/support/syscall-gen/types+openbsd:6.2-x64.frag b/support/syscall-gen/types+openbsd:6.2-x64.frag
index 8d48229e..7747a9b7 100644
--- a/support/syscall-gen/types+openbsd:6.2-x64.frag
+++ b/support/syscall-gen/types+openbsd:6.2-x64.frag
@@ -48,13 +48,13 @@ type rlimit = struct
 ;;
 
 type timespec = struct
-	sec	: uint64
-	nsec	: uint64 
+	sec	: int64
+	nsec	: int64
 ;;
 
 type timeval = struct
-	sec	: uint64
-	usec	: uint64
+	sec	: int64
+	usec	: int64
 ;;
 
 type timezone = struct
diff --git a/support/syscall-gen/types+openbsd:6.3-x64.frag b/support/syscall-gen/types+openbsd:6.3-x64.frag
index cd204e59..40f0f03f 100644
--- a/support/syscall-gen/types+openbsd:6.3-x64.frag
+++ b/support/syscall-gen/types+openbsd:6.3-x64.frag
@@ -49,13 +49,13 @@ type rlimit = struct
 ;;
 
 type timespec = struct
-	sec	: uint64
-	nsec	: uint64 
+	sec	: int64
+	nsec	: int64
 ;;
 
 type timeval = struct
-	sec	: uint64
-	usec	: uint64
+	sec	: int64
+	usec	: int64
 ;;
 
 type timezone = struct
-- 
2.18.0

 ---- On Tue, 14 Aug 2018 22:33:38 -0700 Ori Bernstein <ori@xxxxxxxxxxxxxx> wrote ---- 
 > On Sat, 11 Aug 2018 19:11:19 -0700, iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote: 
 >  
 > > Every single conversion except for one for OS X is uint64 to int64. 
 > >  
 > > --- 
 > >  lib/std/syswrap+posixy.myr                    |  2 +- 
 > >  lib/std/syswrap-ss+freebsd.myr                |  4 ++-- 
 > >  lib/std/syswrap-ss+linux.myr                  |  4 ++-- 
 > >  lib/std/syswrap-ss+netbsd.myr                 |  4 ++-- 
 > >  lib/std/syswrap-ss+openbsd.myr                |  4 ++-- 
 > >  lib/std/syswrap-ss+osx.myr                    |  4 ++-- 
 >  
 > >  lib/sys/sys+freebsd-x64.myr                   |  8 +++---- 
 > >  lib/sys/sys+linux-x64.myr                     |  8 +++---- 
 > >  lib/sys/sys+netbsd-x64.myr                    |  8 +++---- 
 > >  lib/sys/sys+openbsd-x64.myr                   | 10 ++++---- 
 >  
 > Quick note, we may want to these changes into our 
 > syscall generation code. Right now, that bit is 
 > crappy (we don't automatically regenerate system 
 > call files), but we should at least be keeping 
 > things in sync so that when we add new, say, 
 > OpenBSD releases, things don't mysteriously 
 > go out of sync. 
 >  
 > Take a look at mc/support/syscall-gen 
 >  
 >  
 > --  
 >     Ori Bernstein 
 >  
 > 



References:
[PATCH 1/4] Make timespec/timeval struct members signed to simplify arithmetic.iriri <iri@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Re: [PATCH 1/4] Make timespec/timeval struct members signed to simplify arithmetic.Ori Bernstein <ori@xxxxxxxxxxxxxx>