Skip to content

Commit 3abf835

Browse files
committed
l8
1 parent f68465b commit 3abf835

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

x/cc.k

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ cc:{[o]opts::o
1212
i:i@&{(2~|/(T 1_c)?`swc`stm)&3=#c:&P=x}'i:&T=`cnd /keep ternary
1313
rwcnd'|j@&~(j:&(~`=S)&(T=`cnd)|T=`swc)?\i /rewrite cnd/swc expressions
1414
S[0]:$[(#o)~i:o?`lib;S 0;o 1+i] /emit`lib`name (instead of main + remove func main)
15+
$[`l8?o;cctype::`i`u`j`k`f!("int";"uint";"long";"ulong";"double");0]
1516
n:{x[y]+:1}/(,&#P),P;n[0]-:1; /number of children per node
1617
s:{c:(0,(#x)-z)^x /cut args from stack
1718
(c 0),,,/(F T y)[y;|c 1]}/[();|!#P;|n] /fold over the tree in reverse order
@@ -37,8 +38,8 @@ ccprg:{
3738
fncs: ,/y@&`fun=T c:1_&P=0
3839
cons:nl y@&`con=T c
3940
vars:nl y@&`var=T c
40-
runt:$[`nort?opts;"";ccrnt]
41-
main:$[|/`nort`lib?\opts;"";ccmain]
41+
runt:$[`nort?opts;"";`l8?opts;<`"l8.h";ccrnt]
42+
main:$[|/`nort`lib?\opts;"";`l8?opts;"void cmain(char**a){argv=a;main_();}";ccmain]
4243
data:$[#D;"memcpy(M_,\"",("\\x","\\x"/(#D)^`x D),"\",",($#D),");";""]
4344
tabl:nl y@&`tab=T c
4445
tabl:$[#tabl;"F_=malloc(",($1+|/I@&`tab=T),"*sizeof(void*));\n";""],tabl

x/l86.c renamed to x/l8.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
//gcc -Os -s -nostdlib -static -Wl,--nmagic -Wl,--build-id=none -fno-asynchronous-unwind-tables k.c
33
//(objcopy --remove-section .comment a.out b.out)
44

5-
typedef uint unsigned int;
6-
typedef ulong unsigned long;
5+
typedef unsigned int uint;
6+
typedef unsigned long ulong;
77

88
asm(".globl _start;_start:mov %rsp,%rdi;call cmain");
99

1010

11-
static double F64copysign(double x,double y){union{double f;uint64_t i;}ux={x},uy={y};ux.i&=-1ull/2;ux.i|=uy.i&1ull<<63;return ux.f;}
11+
static double F64copysign(double x,double y){union{double f;ulong i;}ux={x},uy={y};ux.i&=-1ul/2;ux.i|=uy.i&1ul<<63;return ux.f;}
1212
static double F64floor(double x){int i=(int)x;return(double)i;}
1313
__attribute((naked))static double F64abs(double x){ asm("xor %eax,%eax;dec %rax;shr %rax;movq %rax,%xmm1;andpd %xmm1,%xmm0;ret;");}
1414
__attribute((naked))static double F64sqrt(double x){ asm("sqrtsd %xmm0,%xmm0;ret");}
@@ -49,4 +49,4 @@ static int ReadIn(int dst,int n){return(int)read(1,_M+dst,n);}
4949
static long Native(long x,long y){return(x+y)*0;}
5050
static void panic(int x){Exit(1);}
5151

52-
void cmain(char**a){argv=a;main_();}
52+
//void cmain(char**a){argv=a;main_();}

x/mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ set -x
44
#go install /c/k/wg/cmd/wg
55
#wg -k .. > k.k
66

7-
gcc -nostdlib -static l86.c
8-
exit 0
9-
107
if [ "$1" = "go" ]; then
118
k k.k go.k -e 'x:`<go`pkg`k' > kg.go
129
go fmt kg.go
@@ -23,6 +20,10 @@ elif [ "$1" = "cc" ]; then
2320
#c:/local/zig/zig cc -Wall -Wno-parentheses-equality -fwrapv -ffast-math k.c -o kc.exe -lm
2421
elif [ "$1" = "ctest" ]; then
2522
./kc ../k.t -e
23+
elif [ "$1" = "l8" ]; then
24+
k k.k cc.k -e 'x:`<cc``l8' > k.c
25+
#gcc -Wall -Wfatal-errors -Os -s -nostdlib -static -Wl,--nmagic -Wl,--build-id=none -fno-asynchronous-unwind-tables -ol8 k.c
26+
gcc -Wall -Wfatal-errors -ol8 k.c -lm
2627
elif [ "$1" = "wa" ]; then
2728
k k.k wa.k -e 'x:`<wa``' > k.wa
2829
/c/local/wabt/wat2wasm k.wa

0 commit comments

Comments
 (0)