# HG changeset patch # User Nobuyasu Oshiro # Date 1335614513 -32400 # Node ID 536b29f11352c5db997abe857c4a349451f83b50 add some files diff -r 000000000000 -r 536b29f11352 echoServer/echoClient.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/echoServer/echoClient.k Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,24 @@ +using konoha.socket.*; +using konoha.io.*; + +void main(String[] args) +{ + int port = 8888; + String host = "localhost"; + print "port number = " + port; + print "host = " + host; + + Socket sock = new Socket(host, port); + + InputStream in = sock.getInputStream(); + OutputStream out = sock.getOutputStream(); + + out <<< "test" <<< EOL; + out.flush(); + String b = in.readLine(); + print b; + in.close(); + out.close(); + + +} \ No newline at end of file diff -r 000000000000 -r 536b29f11352 echoServer/echoServer.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/echoServer/echoServer.c Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,76 @@ +/* + * http://blog.majide.com/2009/02/socket-programming-server/ + */ + + +#include +#include +#include +#include +#include +#include +#include + +#define PORT 8888 +#define MAXDATA 2048 + +int main() +{ + struct sockaddr_in saddr; + struct sockaddr_in caddr; + + int listen_fd; + int conn_fd; + + int len = sizeof(struct sockaddr_in); + + int rsize; + char buf[MAXDATA]; + + if ((listen_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + perror("socket"); + exit(EXIT_FAILURE); + } + + bzero((char *)&saddr, sizeof(saddr)); + + saddr.sin_family = PF_INET; + saddr.sin_addr.s_addr = INADDR_ANY; + saddr.sin_port = htons(PORT); + if (bind(listen_fd, (struct sockaddr *)&saddr, len) < 0) { + perror("bind"); + exit(EXIT_FAILURE); + } + + if (listen(listen_fd, SOMAXCONN) < 0) { + perror("listen"); + exit(EXIT_FAILURE); + } + printf("Start Listening Port : %d", PORT); + + if ((conn_fd = accept(listen_fd, (struct sockaddr *)&caddr, &len)) < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + printf("\nconn_fd = %d\n",conn_fd); + close(listen_fd); + do { + rsize = recv(conn_fd, buf, MAXDATA, 0); + if (rsize == 0) { + break; + } else if (rsize == -1) { + perror("recv"); + exit(EXIT_FAILURE); + } else { + write(conn_fd, buf, rsize); + } + } while(1); + + if ( close(conn_fd) < 0) { + perror("error"); + exit(EXIT_FAILURE); + } + + printf("Connection close.\n"); + return 0; +} diff -r 000000000000 -r 536b29f11352 echoServer/echoServer.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/echoServer/echoServer.k Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,23 @@ +using konoha.socket.*; +using konoha.io.*; + +void main(String[] args) +{ + int port = 8888; + print "port number = " + port; + ServerSocket servSock = new ServerSocket(port, 1); + + print "accept..." + Socket sock = servSock.accept(); + print "accepted" + + InputStream in = sock.getInputStream(); + OutputSteram out = sock.getOutputStream(); + + while ( !in.isClosed() ) { + String b = in.readLine(); + print b; + out <<< b <<< EOL; + out.flush(); + } +} diff -r 000000000000 -r 536b29f11352 error/modifyMissType.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/error/modifyMissType.k Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,8 @@ +int f() { + return 3; +} + +void main(String[] args) { + String a = f(); + String b = f(); +} \ No newline at end of file diff -r 000000000000 -r 536b29f11352 error/returnValue.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/error/returnValue.k Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,11 @@ +void f() { + return 0; +} +byte g() { + return 0; +} + +void main(String[] args) { + f(); + g(); +} diff -r 000000000000 -r 536b29f11352 factorial/factorial.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/factorial/factorial.k Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,17 @@ +def factorial(n) { + if(n == 1) 1; + return n * factorial(n-1); +} + +void main(String[] args) { +// OUT << "output test" << EOL; + unsigned int result; + if(args.size > 0) { + result = factorial((int)args[0]); + print "factorial(" + args[0] +")"; + } else { + result = factorial(3); + print "factorial(3)"; + } + print result; +} diff -r 000000000000 -r 536b29f11352 test/addField.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/addField.k Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,22 @@ + +class PersonA { + String name; +} + +@Expando class PersonB { + String name; +} + +void main(String[] args) { + + PersonA p = new PersonA(); + p.name = "maro"; +// p.age = 22; // error + print p.name; + + pp = new PersonB(); + pp.name = "goro"; + pp.age = 22; + print pp.name + ":" + pp.age + +} \ No newline at end of file diff -r 000000000000 -r 536b29f11352 test/math.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/math.k Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,49 @@ +using konoha.math.*; + +void main(String[] args) { + int x, y; + if (args.size > 2 ) { + x = (int)args[0]; + y = (int)args[1]; + } else if (args.size == 1) { + x = (int)args[0]; + y = 45; + } else { + x = 45; + y = 45; + } + int e,d; + e = 10; + d = 3; + + print "x = " + x; + print "y = " + y; + print "e = " + e; + print "d = " + d; + + print "Math.abs(x) = " + Math.abs(x); + print "Math.fabs(x) = " + Math.fabs(x); + print "Math.pow(x,y) = " + Math.pow(x,y); + print "Math.ldexp( x, e) = " + Math.ldexp( x, e); + print "Math.modf( x, y) = " + Math.modf( x, y); + print "Math.frexp( x, y) = " + Math.frexp( x, y); + print "Math.fmod( x, d) = " + Math.fmod( x, d); + print "Math.ceil( x) = " + Math.ceil( x); + print "Math.floor(x) = " + Math.floor(x); + print "Math.sqrt(x) = " + Math.sqrt(x); + print "Math.exp(x) = " + Math.exp(x); + print "Math.log10(x) = " + Math.log10(x); + print "Math.log(x) = " + Math.log(x); + print "Math.sin(x) = " + Math.sin(x); + print "Math.cos(x) = " + Math.cos(x); + print "Math.tan(x) = " + Math.tan(x); + print "Math.asin(x) = " + Math.asin(x); + print "Math.acos(x) = " + Math.acos(x); + print "Math.atan(x) = " + Math.atan(x); + print "Math.atan2(x, y) = " + Math.atan2(x, y); + print "Math.sinh(x) = " + Math.sinh(x); + print "Math.cosh(x) = " + Math.cosh(x); + print "Math.tanh(x) = " + Math.tanh(x); + + +} \ No newline at end of file diff -r 000000000000 -r 536b29f11352 test/out.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/out.k Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,13 @@ +void main(String[] args) { + int size = 0; + OutputStream out = new OutputStream("output.txt"); + String m = "out put test"; + out <<< m <<< EOL; + if(args.size > 0) { + out <<< args[0] <<< EOL; + } + else { + out <<< "test" <<< EOL; + } + out.close(); +} \ No newline at end of file diff -r 000000000000 -r 536b29f11352 test/output.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/output.txt Sat Apr 28 21:01:53 2012 +0900 @@ -0,0 +1,2 @@ +out put test +test