@@ -2,6 +2,9 @@ enum fn {
22#ifdef BLAS
33 nrm2 , asum , imax , rot , mv ,
44#endif
5+ #ifdef CURL
6+ curl ,
7+ #endif
58};
69void reg (int64_t id , int64_t name , int32_t arity ){
710 int64_t l = ti (14 ,(uint32_t )l2 (id , Ku (name )));
@@ -14,7 +17,10 @@ void libs(void){ //encode strings with: https://play.golang.org/p/4ethx6OEVCR
1417 reg (asum ,1836413793ull ,1 );
1518 reg (imax ,2019650921ull ,1 );
1619 reg (rot , 7630706ull ,4 );
17- reg (mv , 30317ull , 7 );
20+ reg (mv , 30317ull ,7 );
21+ #endif
22+ #ifdef CURL
23+ reg (curl ,1819440483ull ,1 );
1824#endif
1925}
2026
@@ -41,6 +47,16 @@ void cblas_dgemv(int,int,int,int,double,double*,int,double*,int,double,double*,i
4147#define trans (x ) (111+x)
4248#endif
4349
50+ #ifdef CURL
51+ void * curl_easy_init (void );
52+ int curl_easy_perform (void * );
53+ void curl_easy_setopt (void * ,int ,void * );
54+ void curl_easy_cleanup (void * );
55+ static size_t curlback (void * c ,size_t n ,size_t m ,uint64_t * r ){
56+ uint64_t x = * r ;int32_t xn = nn (x );n *=m ;x = uspc (x ,Ct ,n );* r = x ;
57+ memcpy (M_ + (int32_t )x + xn ,c ,n );return n ;}
58+ #endif
59+
4460double * FK (uint64_t x ){return (double * )(M_ + (int32_t )x ); }
4561double f0 (uint64_t x ){return F64 ((int32_t )I64 ((int32_t )x ));}
4662double f1 (uint64_t x ){return F64 ((int32_t )I64 ((int32_t )x + 8 ));}
@@ -49,6 +65,7 @@ int32_t i2(uint64_t x){return I32((int32_t)I64((int32_t)x+16));}
4965int32_t i3 (uint64_t x ){return I32 ((int32_t )I64 ((int32_t )x + 24 ));}
5066void dim (uint64_t A ,int32_t rA ,int32_t * m ,int32_t * n ){rA < 0 ?(* m = - rA ,* n = - rA /nn (A )):(* m = rA ,* n = rA /nn (A ));}
5167
68+
5269//x:function-id(not refcounted), y:list of args(length arity)
5370int64_t cnative (int64_t x , int64_t y ){
5471 int32_t m ,n ,i ;
@@ -77,7 +94,20 @@ int64_t cnative(int64_t x, int64_t y){
7794 printf ("todo mv complex\n" );
7895 }
7996 };
97+ #endif
98+ #ifdef CURL
99+ case curl :{x = Fst (y );if (tp (x )!= Ct )trap ();x = cat1 (x ,Kc (0 ));
100+ void * c = curl_easy_init ();
101+ curl_easy_setopt (c ,10002 ,M_ + (int32_t )x );
102+ uint64_t r = mk (Ct ,0 );
103+ curl_easy_setopt (c ,20011 ,curlback );
104+ curl_easy_setopt (c ,10001 ,(void * )& r );
105+ curl_easy_setopt (c ,10018 ,"libcurl-agent/1.0" );
106+ if (curl_easy_perform (c ))trap ();
107+ curl_easy_cleanup (c );
108+ dx (x );return r ;}
80109#endif
81110 default : return y ;
82111}}
83112
113+
0 commit comments