Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
03febb67
Commit
03febb67
authored
Jun 30, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up rearrangement of runtime functions in the source
add isNaN, isInf, NaN, Inf SVN=125389
parent
d3204ef1
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
585 additions
and
525 deletions
+585
-525
src/cmd/gc/sys.go
src/cmd/gc/sys.go
+9
-1
src/cmd/gc/sysimport.c
src/cmd/gc/sysimport.c
+115
-95
src/runtime/runtime.c
src/runtime/runtime.c
+461
-0
src/runtime/runtime_map.c
src/runtime/runtime_map.c
+0
-429
No files found.
src/cmd/gc/sys.go
View file @
03febb67
...
...
@@ -31,6 +31,10 @@ func envv(int32) string;
func
frexp
(
float64
)
(
int32
,
float64
);
// break fp into exp,fract
func
ldexp
(
int32
,
float64
)
float64
;
// make fp from exp,fract
func
modf
(
float64
)
(
float64
,
float64
);
// break fp into double.double
func
isInf
(
float64
,
int32
)
bool
;
// test for infinity
func
isNaN
(
float64
)
bool
;
// test for not-a-number
func
Inf
(
int32
)
float64
;
// return signed Inf
func
NaN
()
float64
;
// return a NaN
func
newmap
(
keysize
uint32
,
valsize
uint32
,
keyalg
uint32
,
valalg
uint32
,
...
...
@@ -42,7 +46,7 @@ func mapassign2(hmap *map[any]any, key any, val any, pres bool);
func
readfile
(
string
)
(
string
,
bool
);
// read file into string; boolean status
func
exit
(
int32
);
func
exit
(
int32
);
export
mal
...
...
@@ -75,6 +79,10 @@ export
frexp
ldexp
modf
isInf
,
isNaN
,
Inf
,
NaN
,
// op map
newmap
...
...
src/cmd/gc/sysimport.c
View file @
03febb67
This diff is collapsed.
Click to expand it.
src/runtime/runtime.c
View file @
03febb67
...
...
@@ -109,3 +109,464 @@ sys·mal(uint32 n, uint8 *ret)
ret
=
mal
(
n
);
FLUSH
(
&
ret
);
}
static
Map
*
hash
[
1009
];
static
Map
*
hashmap
(
Sigi
*
si
,
Sigs
*
ss
)
{
int32
ns
,
ni
;
uint32
ihash
,
h
;
byte
*
sname
,
*
iname
;
Map
*
m
;
h
=
((
uint32
)
si
+
(
uint32
)
ss
)
%
nelem
(
hash
);
for
(
m
=
hash
[
h
];
m
!=
nil
;
m
=
m
->
link
)
{
if
(
m
->
si
==
si
&&
m
->
ss
==
ss
)
{
if
(
m
->
bad
)
{
throw
(
"bad hashmap"
);
m
=
nil
;
}
// prints("old hashmap\n");
return
m
;
}
}
ni
=
si
[
0
].
offset
;
// first word has size
m
=
mal
(
sizeof
(
*
m
)
+
ni
*
sizeof
(
m
->
fun
[
0
]));
m
->
si
=
si
;
m
->
ss
=
ss
;
ni
=
1
;
// skip first word
ns
=
0
;
loop1:
// pick up next name from
// interface signature
iname
=
si
[
ni
].
name
;
if
(
iname
==
nil
)
{
m
->
link
=
hash
[
h
];
hash
[
h
]
=
m
;
// prints("new hashmap\n");
return
m
;
}
ihash
=
si
[
ni
].
hash
;
loop2:
// pick up and comapre next name
// from structure signature
sname
=
ss
[
ns
].
name
;
if
(
sname
==
nil
)
{
prints
((
int8
*
)
iname
);
prints
(
": "
);
throw
(
"hashmap: failed to find method"
);
m
->
bad
=
1
;
m
->
link
=
hash
[
h
];
hash
[
h
]
=
m
;
return
nil
;
}
if
(
ihash
!=
ss
[
ns
].
hash
||
strcmp
(
sname
,
iname
)
!=
0
)
{
ns
++
;
goto
loop2
;
}
m
->
fun
[
si
[
ni
].
offset
]
=
ss
[
ns
].
fun
;
ni
++
;
goto
loop1
;
}
void
sys
·
ifaces2i
(
Sigi
*
si
,
Sigs
*
ss
,
Map
*
m
,
void
*
s
)
{
if
(
debug
)
{
prints
(
"s2i sigi="
);
sys
·
printpointer
(
si
);
prints
(
" sigs="
);
sys
·
printpointer
(
ss
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
}
if
(
s
==
nil
)
{
throw
(
"ifaces2i: nil pointer"
);
m
=
nil
;
FLUSH
(
&
m
);
return
;
}
m
=
hashmap
(
si
,
ss
);
if
(
debug
)
{
prints
(
" returning m="
);
sys
·
printpointer
(
m
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
prints
(
"
\n
"
);
dump
((
byte
*
)
m
,
64
);
}
FLUSH
(
&
m
);
}
void
sys
·
ifacei2i
(
Sigi
*
si
,
Map
*
m
,
void
*
s
)
{
if
(
debug
)
{
prints
(
"i2i sigi="
);
sys
·
printpointer
(
si
);
prints
(
" m="
);
sys
·
printpointer
(
m
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
}
if
(
m
==
nil
)
{
throw
(
"ifacei2i: nil map"
);
s
=
nil
;
FLUSH
(
&
s
);
return
;
}
if
(
m
->
si
==
nil
)
{
throw
(
"ifacei2i: nil pointer"
);
return
;
}
if
(
m
->
si
!=
si
)
{
m
=
hashmap
(
si
,
m
->
ss
);
FLUSH
(
&
m
);
}
if
(
debug
)
{
prints
(
" returning m="
);
sys
·
printpointer
(
m
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
prints
(
"
\n
"
);
dump
((
byte
*
)
m
,
64
);
}
}
void
sys
·
ifacei2s
(
Sigs
*
ss
,
Map
*
m
,
void
*
s
)
{
if
(
debug
)
{
prints
(
"i2s m="
);
sys
·
printpointer
(
m
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
prints
(
"
\n
"
);
}
if
(
m
==
nil
)
{
throw
(
"ifacei2s: nil map"
);
s
=
nil
;
FLUSH
(
&
s
);
return
;
}
if
(
m
->
ss
!=
ss
)
{
dump
((
byte
*
)
m
,
64
);
throw
(
"ifacei2s: wrong pointer"
);
s
=
nil
;
FLUSH
(
&
s
);
return
;
}
}
enum
{
NANEXP
=
2047
<<
20
,
NANMASK
=
2047
<<
20
,
NANSIGN
=
1
<<
31
,
};
static
uint64
uvnan
=
0x7FF0000000000001
;
static
uint64
uvinf
=
0x7FF0000000000000
;
static
uint64
uvneginf
=
0xFFF0000000000000
;
static
int32
isInf
(
float64
d
,
int32
sign
)
{
uint64
x
;
x
=
*
(
uint64
*
)
&
d
;
if
(
sign
==
0
)
{
if
(
x
==
uvinf
||
x
==
uvneginf
)
return
1
;
return
0
;
}
if
(
sign
>
0
)
{
if
(
x
==
uvinf
)
return
1
;
return
0
;
}
if
(
x
==
uvneginf
)
return
1
;
return
0
;
}
static
float64
NaN
(
void
)
{
return
*
(
float64
*
)
&
uvnan
;
}
static
int32
isNaN
(
float64
d
)
{
uint64
x
;
x
=
*
(
uint64
*
)
&
d
;
return
((
uint32
)
x
>>
32
)
==
0x7FF00000
&&
!
isInf
(
d
,
0
);
}
static
float64
Inf
(
int32
sign
)
{
if
(
sign
<
0
)
return
*
(
float64
*
)
&
uvinf
;
else
return
*
(
float64
*
)
&
uvneginf
;
}
enum
{
MASK
=
0x7ffL
,
SHIFT
=
64
-
11
-
1
,
BIAS
=
1022L
,
};
static
float64
frexp
(
float64
d
,
int32
*
ep
)
{
uint64
x
;
if
(
d
==
0
)
{
*
ep
=
0
;
return
0
;
}
x
=
*
(
uint64
*
)
&
d
;
*
ep
=
(
int32
)((
x
>>
SHIFT
)
&
MASK
)
-
BIAS
;
x
&=
~
((
uint64
)
MASK
<<
SHIFT
);
x
|=
(
uint64
)
BIAS
<<
SHIFT
;
return
*
(
float64
*
)
&
x
;
}
static
float64
ldexp
(
float64
d
,
int32
e
)
{
uint64
x
;
if
(
d
==
0
)
return
0
;
x
=
*
(
uint64
*
)
&
d
;
e
+=
(
int32
)(
x
>>
SHIFT
)
&
MASK
;
if
(
e
<=
0
)
return
0
;
/* underflow */
if
(
e
>=
MASK
){
/* overflow */
if
(
d
<
0
)
return
Inf
(
-
1
);
return
Inf
(
1
);
}
x
&=
~
((
uint64
)
MASK
<<
SHIFT
);
x
|=
(
uint64
)
e
<<
SHIFT
;
return
*
(
float64
*
)
&
x
;
}
static
float64
modf
(
float64
d
,
float64
*
ip
)
{
float64
dd
;
uint64
x
;
int32
e
;
if
(
d
<
1
)
{
if
(
d
<
0
)
{
d
=
modf
(
-
d
,
ip
);
*
ip
=
-*
ip
;
return
-
d
;
}
*
ip
=
0
;
return
d
;
}
x
=
*
(
uint64
*
)
&
d
;
e
=
(
int32
)((
x
>>
SHIFT
)
&
MASK
)
-
BIAS
;
/*
* Keep the top 11+e bits; clear the rest.
*/
if
(
e
<=
64
-
11
)
x
&=
~
((
uint64
)
1
<<
(
64
-
11
-
e
))
-
1
;
dd
=
*
(
float64
*
)
&
x
;
*
ip
=
dd
;
return
d
-
dd
;
}
// func frexp(float64) (int32, float64); // break fp into exp,fract
void
sys
·
frexp
(
float64
din
,
int32
iou
,
float64
dou
)
{
dou
=
frexp
(
din
,
&
iou
);
FLUSH
(
&
dou
);
}
//func ldexp(int32, float64) float64; // make fp from exp,fract
void
sys
·
ldexp
(
float64
din
,
int32
ein
,
float64
dou
)
{
dou
=
ldexp
(
din
,
ein
);
FLUSH
(
&
dou
);
}
//func modf(float64) (float64, float64); // break fp into double+double
float64
sys
·
modf
(
float64
din
,
float64
dou1
,
float64
dou2
)
{
dou1
=
modf
(
din
,
&
dou2
);
FLUSH
(
&
dou2
);
}
//func isinf(float64, int32 sign) bool; // test for infinity
void
sys
·
isInf
(
float64
din
,
int32
signin
,
bool
out
)
{
out
=
isInf
(
din
,
signin
);
FLUSH
(
&
out
);
}
//func isnan(float64) bool; // test for NaN
void
sys
·
isNaN
(
float64
din
,
bool
out
)
{
out
=
isNaN
(
din
);
FLUSH
(
&
out
);
}
//func inf(int32 sign) float64; // signed infinity
void
sys
·
Inf
(
int32
signin
,
float64
out
)
{
out
=
Inf
(
signin
);
FLUSH
(
&
out
);
}
//func nan() float64; // NaN
void
sys
·
NaN
(
float64
out
)
{
out
=
NaN
();
FLUSH
(
&
out
);
}
static
int32
argc
;
static
uint8
**
argv
;
static
int32
envc
;
static
uint8
**
envv
;
void
args
(
int32
c
,
uint8
**
v
)
{
argc
=
c
;
argv
=
v
;
envv
=
v
+
argc
+
1
;
// skip 0 at end of argv
for
(
envc
=
0
;
envv
[
envc
]
!=
0
;
envc
++
)
;
}
//func argc() int32; // return number of arguments
void
sys
·
argc
(
int32
v
)
{
v
=
argc
;
FLUSH
(
&
v
);
}
//func envc() int32; // return number of environment variables
void
sys
·
envc
(
int32
v
)
{
v
=
envc
;
FLUSH
(
&
v
);
}
//func argv(i) string; // return argument i
void
sys
·
argv
(
int32
i
,
string
s
)
{
uint8
*
str
;
int32
l
;
if
(
i
<
0
||
i
>=
argc
)
{
s
=
emptystring
;
goto
out
;
}
str
=
argv
[
i
];
l
=
findnull
((
int8
*
)
str
);
s
=
mal
(
sizeof
(
s
->
len
)
+
l
);
s
->
len
=
l
;
mcpy
(
s
->
str
,
str
,
l
);
out:
FLUSH
(
&
s
);
}
//func envv(i) string; // return argument i
void
sys
·
envv
(
int32
i
,
string
s
)
{
uint8
*
str
;
int32
l
;
if
(
i
<
0
||
i
>=
envc
)
{
s
=
emptystring
;
goto
out
;
}
str
=
envv
[
i
];
l
=
findnull
((
int8
*
)
str
);
s
=
mal
(
sizeof
(
s
->
len
)
+
l
);
s
->
len
=
l
;
mcpy
(
s
->
str
,
str
,
l
);
out:
FLUSH
(
&
s
);
}
check
(
void
)
{
int8
a
;
uint8
b
;
int16
c
;
uint16
d
;
int32
e
;
uint32
f
;
int64
g
;
uint64
h
;
float32
i
;
float64
j
;
void
*
k
;
uint16
*
l
;
if
(
sizeof
(
a
)
!=
1
)
throw
(
"bad a"
);
if
(
sizeof
(
b
)
!=
1
)
throw
(
"bad b"
);
if
(
sizeof
(
c
)
!=
2
)
throw
(
"bad c"
);
if
(
sizeof
(
d
)
!=
2
)
throw
(
"bad d"
);
if
(
sizeof
(
e
)
!=
4
)
throw
(
"bad e"
);
if
(
sizeof
(
f
)
!=
4
)
throw
(
"bad f"
);
if
(
sizeof
(
g
)
!=
8
)
throw
(
"bad g"
);
if
(
sizeof
(
h
)
!=
8
)
throw
(
"bad h"
);
if
(
sizeof
(
i
)
!=
4
)
throw
(
"bad i"
);
if
(
sizeof
(
j
)
!=
8
)
throw
(
"bad j"
);
if
(
sizeof
(
k
)
!=
8
)
throw
(
"bad k"
);
if
(
sizeof
(
l
)
!=
8
)
throw
(
"bad l"
);
// prints(1"check ok\n");
initsig
();
}
src/runtime/runtime_map.c
View file @
03febb67
...
...
@@ -4,435 +4,6 @@
#include "runtime.h"
static
Map
*
hash
[
1009
];
static
Map
*
hashmap
(
Sigi
*
si
,
Sigs
*
ss
)
{
int32
ns
,
ni
;
uint32
ihash
,
h
;
byte
*
sname
,
*
iname
;
Map
*
m
;
h
=
((
uint32
)
si
+
(
uint32
)
ss
)
%
nelem
(
hash
);
for
(
m
=
hash
[
h
];
m
!=
nil
;
m
=
m
->
link
)
{
if
(
m
->
si
==
si
&&
m
->
ss
==
ss
)
{
if
(
m
->
bad
)
{
throw
(
"bad hashmap"
);
m
=
nil
;
}
// prints("old hashmap\n");
return
m
;
}
}
ni
=
si
[
0
].
offset
;
// first word has size
m
=
mal
(
sizeof
(
*
m
)
+
ni
*
sizeof
(
m
->
fun
[
0
]));
m
->
si
=
si
;
m
->
ss
=
ss
;
ni
=
1
;
// skip first word
ns
=
0
;
loop1:
// pick up next name from
// interface signature
iname
=
si
[
ni
].
name
;
if
(
iname
==
nil
)
{
m
->
link
=
hash
[
h
];
hash
[
h
]
=
m
;
// prints("new hashmap\n");
return
m
;
}
ihash
=
si
[
ni
].
hash
;
loop2:
// pick up and comapre next name
// from structure signature
sname
=
ss
[
ns
].
name
;
if
(
sname
==
nil
)
{
prints
((
int8
*
)
iname
);
prints
(
": "
);
throw
(
"hashmap: failed to find method"
);
m
->
bad
=
1
;
m
->
link
=
hash
[
h
];
hash
[
h
]
=
m
;
return
nil
;
}
if
(
ihash
!=
ss
[
ns
].
hash
||
strcmp
(
sname
,
iname
)
!=
0
)
{
ns
++
;
goto
loop2
;
}
m
->
fun
[
si
[
ni
].
offset
]
=
ss
[
ns
].
fun
;
ni
++
;
goto
loop1
;
}
void
sys
·
ifaces2i
(
Sigi
*
si
,
Sigs
*
ss
,
Map
*
m
,
void
*
s
)
{
if
(
debug
)
{
prints
(
"s2i sigi="
);
sys
·
printpointer
(
si
);
prints
(
" sigs="
);
sys
·
printpointer
(
ss
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
}
if
(
s
==
nil
)
{
throw
(
"ifaces2i: nil pointer"
);
m
=
nil
;
FLUSH
(
&
m
);
return
;
}
m
=
hashmap
(
si
,
ss
);
if
(
debug
)
{
prints
(
" returning m="
);
sys
·
printpointer
(
m
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
prints
(
"
\n
"
);
dump
((
byte
*
)
m
,
64
);
}
FLUSH
(
&
m
);
}
void
sys
·
ifacei2i
(
Sigi
*
si
,
Map
*
m
,
void
*
s
)
{
if
(
debug
)
{
prints
(
"i2i sigi="
);
sys
·
printpointer
(
si
);
prints
(
" m="
);
sys
·
printpointer
(
m
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
}
if
(
m
==
nil
)
{
throw
(
"ifacei2i: nil map"
);
s
=
nil
;
FLUSH
(
&
s
);
return
;
}
if
(
m
->
si
==
nil
)
{
throw
(
"ifacei2i: nil pointer"
);
return
;
}
if
(
m
->
si
!=
si
)
{
m
=
hashmap
(
si
,
m
->
ss
);
FLUSH
(
&
m
);
}
if
(
debug
)
{
prints
(
" returning m="
);
sys
·
printpointer
(
m
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
prints
(
"
\n
"
);
dump
((
byte
*
)
m
,
64
);
}
}
void
sys
·
ifacei2s
(
Sigs
*
ss
,
Map
*
m
,
void
*
s
)
{
if
(
debug
)
{
prints
(
"i2s m="
);
sys
·
printpointer
(
m
);
prints
(
" s="
);
sys
·
printpointer
(
s
);
prints
(
"
\n
"
);
}
if
(
m
==
nil
)
{
throw
(
"ifacei2s: nil map"
);
s
=
nil
;
FLUSH
(
&
s
);
return
;
}
if
(
m
->
ss
!=
ss
)
{
dump
((
byte
*
)
m
,
64
);
throw
(
"ifacei2s: wrong pointer"
);
s
=
nil
;
FLUSH
(
&
s
);
return
;
}
}
enum
{
NANEXP
=
2047
<<
20
,
NANMASK
=
2047
<<
20
,
NANSIGN
=
1
<<
31
,
};
static
uint64
uvnan
=
0x7FF0000000000001
;
static
uint64
uvinf
=
0x7FF0000000000000
;
static
uint64
uvneginf
=
0xFFF0000000000000
;
static
int32
isInf
(
float64
d
,
int32
sign
)
{
uint64
x
;
x
=
*
(
uint64
*
)
&
d
;
if
(
sign
==
0
)
{
if
(
x
==
uvinf
||
x
==
uvneginf
)
return
1
;
return
0
;
}
if
(
sign
>
0
)
{
if
(
x
==
uvinf
)
return
1
;
return
0
;
}
if
(
x
==
uvneginf
)
return
1
;
return
0
;
}
static
float64
NaN
(
void
)
{
return
*
(
float64
*
)
&
uvnan
;
}
static
int32
isNaN
(
float64
d
)
{
uint64
x
;
x
=
*
(
uint64
*
)
&
d
;
return
((
uint32
)
x
>>
32
)
==
0x7FF00000
&&
!
isInf
(
d
,
0
);
}
static
float64
Inf
(
int32
sign
)
{
if
(
sign
<
0
)
return
*
(
float64
*
)
&
uvinf
;
else
return
*
(
float64
*
)
&
uvneginf
;
}
enum
{
MASK
=
0x7ffL
,
SHIFT
=
64
-
11
-
1
,
BIAS
=
1022L
,
};
static
float64
frexp
(
float64
d
,
int32
*
ep
)
{
uint64
x
;
if
(
d
==
0
)
{
*
ep
=
0
;
return
0
;
}
x
=
*
(
uint64
*
)
&
d
;
*
ep
=
(
int32
)((
x
>>
SHIFT
)
&
MASK
)
-
BIAS
;
x
&=
~
((
uint64
)
MASK
<<
SHIFT
);
x
|=
(
uint64
)
BIAS
<<
SHIFT
;
return
*
(
float64
*
)
&
x
;
}
static
float64
ldexp
(
float64
d
,
int32
e
)
{
uint64
x
;
if
(
d
==
0
)
return
0
;
x
=
*
(
uint64
*
)
&
d
;
e
+=
(
int32
)(
x
>>
SHIFT
)
&
MASK
;
if
(
e
<=
0
)
return
0
;
/* underflow */
if
(
e
>=
MASK
){
/* overflow */
if
(
d
<
0
)
return
Inf
(
-
1
);
return
Inf
(
1
);
}
x
&=
~
((
uint64
)
MASK
<<
SHIFT
);
x
|=
(
uint64
)
e
<<
SHIFT
;
return
*
(
float64
*
)
&
x
;
}
static
float64
modf
(
float64
d
,
float64
*
ip
)
{
float64
dd
;
uint64
x
;
int32
e
;
if
(
d
<
1
)
{
if
(
d
<
0
)
{
d
=
modf
(
-
d
,
ip
);
*
ip
=
-*
ip
;
return
-
d
;
}
*
ip
=
0
;
return
d
;
}
x
=
*
(
uint64
*
)
&
d
;
e
=
(
int32
)((
x
>>
SHIFT
)
&
MASK
)
-
BIAS
;
/*
* Keep the top 11+e bits; clear the rest.
*/
if
(
e
<=
64
-
11
)
x
&=
~
((
uint64
)
1
<<
(
64
-
11
-
e
))
-
1
;
dd
=
*
(
float64
*
)
&
x
;
*
ip
=
dd
;
return
d
-
dd
;
}
// func frexp(float64) (int32, float64); // break fp into exp,fract
void
sys
·
frexp
(
float64
din
,
int32
iou
,
float64
dou
)
{
dou
=
frexp
(
din
,
&
iou
);
FLUSH
(
&
dou
);
}
//func ldexp(int32, float64) float64; // make fp from exp,fract
void
sys
·
ldexp
(
float64
din
,
int32
ein
,
float64
dou
)
{
dou
=
ldexp
(
din
,
ein
);
FLUSH
(
&
dou
);
}
//func modf(float64) (float64, float64); // break fp into double+double
float64
sys
·
modf
(
float64
din
,
float64
dou1
,
float64
dou2
)
{
dou1
=
modf
(
din
,
&
dou2
);
FLUSH
(
&
dou2
);
}
static
int32
argc
;
static
uint8
**
argv
;
static
int32
envc
;
static
uint8
**
envv
;
void
args
(
int32
c
,
uint8
**
v
)
{
argc
=
c
;
argv
=
v
;
envv
=
v
+
argc
+
1
;
// skip 0 at end of argv
for
(
envc
=
0
;
envv
[
envc
]
!=
0
;
envc
++
)
;
}
//func argc() int32; // return number of arguments
void
sys
·
argc
(
int32
v
)
{
v
=
argc
;
FLUSH
(
&
v
);
}
//func envc() int32; // return number of environment variables
void
sys
·
envc
(
int32
v
)
{
v
=
envc
;
FLUSH
(
&
v
);
}
//func argv(i) string; // return argument i
void
sys
·
argv
(
int32
i
,
string
s
)
{
uint8
*
str
;
int32
l
;
if
(
i
<
0
||
i
>=
argc
)
{
s
=
emptystring
;
goto
out
;
}
str
=
argv
[
i
];
l
=
findnull
((
int8
*
)
str
);
s
=
mal
(
sizeof
(
s
->
len
)
+
l
);
s
->
len
=
l
;
mcpy
(
s
->
str
,
str
,
l
);
out:
FLUSH
(
&
s
);
}
//func envv(i) string; // return argument i
void
sys
·
envv
(
int32
i
,
string
s
)
{
uint8
*
str
;
int32
l
;
if
(
i
<
0
||
i
>=
envc
)
{
s
=
emptystring
;
goto
out
;
}
str
=
envv
[
i
];
l
=
findnull
((
int8
*
)
str
);
s
=
mal
(
sizeof
(
s
->
len
)
+
l
);
s
->
len
=
l
;
mcpy
(
s
->
str
,
str
,
l
);
out:
FLUSH
(
&
s
);
}
check
(
void
)
{
int8
a
;
uint8
b
;
int16
c
;
uint16
d
;
int32
e
;
uint32
f
;
int64
g
;
uint64
h
;
float32
i
;
float64
j
;
void
*
k
;
uint16
*
l
;
if
(
sizeof
(
a
)
!=
1
)
throw
(
"bad a"
);
if
(
sizeof
(
b
)
!=
1
)
throw
(
"bad b"
);
if
(
sizeof
(
c
)
!=
2
)
throw
(
"bad c"
);
if
(
sizeof
(
d
)
!=
2
)
throw
(
"bad d"
);
if
(
sizeof
(
e
)
!=
4
)
throw
(
"bad e"
);
if
(
sizeof
(
f
)
!=
4
)
throw
(
"bad f"
);
if
(
sizeof
(
g
)
!=
8
)
throw
(
"bad g"
);
if
(
sizeof
(
h
)
!=
8
)
throw
(
"bad h"
);
if
(
sizeof
(
i
)
!=
4
)
throw
(
"bad i"
);
if
(
sizeof
(
j
)
!=
8
)
throw
(
"bad j"
);
if
(
sizeof
(
k
)
!=
8
)
throw
(
"bad k"
);
if
(
sizeof
(
l
)
!=
8
)
throw
(
"bad l"
);
// prints(1"check ok\n");
initsig
();
}
typedef
struct
Link
Link
;
typedef
struct
Hmap
Hmap
;
typedef
struct
Alg
Alg
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment