码迷,mamicode.com
首页 > 编程语言 > 详细

5种语言混合编程:C++、JS、python、Lisp、汇编

时间:2014-06-24 20:39:10      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:class   blog   code   http   tar   ext   

/*
混合C++、JS、python、Lisp、汇编
1种语言,5种语法
*/

main
{
	//C++
	vector<int> v;
	v.push(2);
	putsl(v.size());
	if(v.count()==1)
	{
		putsl("abc");
	}

	//JS
	var a=function(x){
		return x*2;
	}
	putsl(a(3));
	a={90,91};
	putsl(a[1]);

	//python
	b=2
	if b==2
		putsl 1 
		putsl 2 
	elif b==3
		putsl 99 

	//Lisp
	[= b 3]
	[rf printl b]
	[= b [+ 1 3]]
	[rf printl b]

	//汇编
	mov b,4
	add b,5
	putsl(b)
}

输出是:

4
abc
6
91
1
2
3
4
9

RPP已经成功从C++内核升级到了lisp内核,欢迎下载试用。

光速编译,无限可能,尽在RPP。(音up)

/*
控制台贪食蛇
*/

int g_std_out
rbuf<int> g_arr
int g_next=10
int g_food

void main()
{
	g_std_out=stdcall("GetStdHandle",-11)
	g_arr.push(105)

	CONSOLE_CURSOR_INFO cur_info
	cur_info.dwSize=1
	cur_info.bVisible=0
	stdcall("SetConsoleCursorInfo",g_std_out,&cur_info)
	rf.cmd("mode con cols=66 lines=35")

	init
	rf.srand	
	start=rf.tick
	food
	
	for
		key
		if rf.tick-start<100
			continue
		start=rf.tick
		ifn check
			return
		g_arr.push_front(g_arr[0]+g_next)
		if g_food!=g_arr[0]
			g_arr.pop
		else
			food
		update
}

void gotoxy(int x,int y)
{
	COORD pos
	pos.x=x
	pos.y=y
	int temp
	mov temp,pos
	stdcall("SetConsoleCursorPosition",g_std_out,temp)
}

void update()
{
	for i=0 to 199
		gotoxy(i%10+1,i/10+1)
		if g_arr.exist(i)
			puts("O")
		elif i==g_food
			puts("$")
		else
			puts(" ")
}

void init()
{
	for i=0 to 11
		for j=0 to 21
			if i==0||i==11||j==0||j==21
				gotoxy(i,j)
				puts("#")
}

void key()
{
	if stdcall("GetAsyncKeyState",0x26)
		temp=-10
	elif stdcall("GetAsyncKeyState",0x28)
		temp=10
	elif stdcall("GetAsyncKeyState",0x25)
		temp=-1
	elif stdcall("GetAsyncKeyState",0x27)
		temp=1
	else
		return
	if g_arr.count<2||g_arr.get(1)!=g_arr.get(0)+temp
		g_next=temp
}

int check()
{
	temp=g_arr[0]+g_next
	if temp<0||temp>199||int.abs(temp%10-g_arr[0]%10)>1||g_arr.exist(temp)
		stdcall("MessageBoxA",0,('over len '+g_arr.count).cstr,"",0)
		return false
	return true
}

void food()
{
	g_food=rf.rand()%200
	if g_arr.exist(g_food)
		food
}

struct CONSOLE_CURSOR_INFO
{
	int dwSize
	bool bVisible
}

struct COORD
{
	ushort x
	ushort y
}

bubuko.com,布布扣


下面是一个彩色版本:

bubuko.com,布布扣


/*
彩色版控制台贪食蛇
*/

int g_std_out
rbuf<int> g_arr
int g_next=10
int g_food

void main()
{
	g_std_out=stdcall("GetStdHandle",-11)
	g_arr.push(105)

	CONSOLE_CURSOR_INFO cur_info
	cur_info.dwSize=1
	cur_info.bVisible=0
	stdcall("SetConsoleCursorInfo",g_std_out,&cur_info)
	rf.cmd("mode con cols=20 lines=21")

	init
	rf.srand	
	start=rf.tick
	food
	
	for
		key
		if rf.tick-start<100
			continue
		start=rf.tick
		ifn check
			return
		g_arr.push_front(g_arr[0]+g_next)
		if g_food!=g_arr[0]
			g_arr.pop
		else
			food
		update
}

void gotoxy(int x,int y)
{
	COORD pos
	pos.x=x
	pos.y=y
	int temp
	mov temp,pos
	stdcall("SetConsoleCursorPosition",g_std_out,temp)
}

void update()
{
	for i=0 to 199
		gotoxy(i%10*2,i/10)
		if g_arr.exist(i)
			out("■")
		elif i==g_food
			out("★")
		else
			puts("  ")
	
}

void init()
{
	stdcall("SetConsoleTextAttribute",g_std_out,0x0a)	
	gotoxy(0,20)
	puts(" ******************")
}

void key()
{
	if stdcall("GetAsyncKeyState",0x26)
		temp=-10
	elif stdcall("GetAsyncKeyState",0x28)
		temp=10
	elif stdcall("GetAsyncKeyState",0x25)
		temp=-1
	elif stdcall("GetAsyncKeyState",0x27)
		temp=1
	else
		return
	if g_arr.count<2||g_arr.get(1)!=g_arr.get(0)+temp
		g_next=temp
}

int check()
{
	temp=g_arr[0]+g_next
	if temp<0||temp>199||int.abs(temp%10-g_arr[0]%10)>1||g_arr.exist(temp)
		stdcall("MessageBoxA",0,('over len '+g_arr.count).cstr,"",0)
		return false
	return true
}

void food()
{
	g_food=rf.rand()%200
	if g_arr.exist(g_food)
		food
}

void out(char* s)
{
	puts(rcode.utf8_to_gbk(s))
}

struct CONSOLE_CURSOR_INFO
{
	int dwSize
	bool bVisible
}

struct COORD
{
	ushort x
	ushort y
}


5种语言混合编程:C++、JS、python、Lisp、汇编,布布扣,bubuko.com

5种语言混合编程:C++、JS、python、Lisp、汇编

标签:class   blog   code   http   tar   ext   

原文地址:http://blog.csdn.net/roundsheep/article/details/33706561

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!