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

/*
混合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
}

下面是一个彩色版本:

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

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、汇编

时间: 2024-08-04 02:06:35

5种语言混合编程:C++、JS、python、Lisp、汇编的相关文章

Swift语言与Objective-C语言混合编程

首先创建一个Swift的Single View工程 然后直接在工程中新建OC文件: 然后选择OC语言之后会问你是否自动创建OC和Swift的中间文件: 然后工程文件夹里就有了三个文件: 现在OC头文件和实现文件中写好一个实例: 然后在Swift语言与Obje...ridging-Header.h文件中 然后就可以直接在swift语言中使用了:

Matlab和C语言混合编程,包含目录的设定

如果.c文件不依赖于任何第三方库,那么mex编译很简单,只需要在matlab的命令行输入 mex test.c 即可. 但是如果这个c文件使用了第三方库文件,如opencv.gsl等等,那么就需要更改一下mex的编译选项,否则会报fetal error C1083,找不到包括文件. 这里需要注意的是,在mex之前,需要使用 mex -setup 选择编译器,假如我选的是VS2012,那么我需要把相应的选项加到VS2012所对应的opt文件中,具体的位置在 ‘MATLAB路径\R2013a\bin

Java语言和C语言混合编程(1)--Java native关键字

可以将native方法比作Java程序同C程序的接口,其实现步骤为:1.编写java源程序,add用native修饰 package p2019.p06; public class NativeAdd { public native int add(int a,int b); } 2.编译java程序,生成NativeAdd.class文件[[email protected] java]# javac p2019/p06/NativeAdd.java生成NativeAdd.class Nativ

C++与Java混合编程

http://www.cnblogs.com/lxshanye/p/3209542.html 现在的程序员,不再像以前一样,掌握一种编程语言就可以混得有模有样了,现实的情况是,真实的项目中,通常是涉及多种编程语言,举几个简单的例子,一个软件为了快速开发,可能是使用Delphi或VB作为界面开发首选语言,底层的指令或核心算法,会使用C/C++处理,涉及数据处理的时候,为了安全和快速开发,会使用Javascript或Python等脚本语言实现数据分析处理.因此,开发者应该学习或掌握语言混合编程. C

java和c++混合编程尝试

下载源代码 现在的程序员,不再像以前一样,掌握一种编程语言就可以混得有模有样了,现实的情况是,真实的项目中,通常是涉及多种编程语言,举几个简单的例子,一个软件为了快速开发,可能是使用 Delphi 或 VB 作为界面开发首选语言,底层的指令或核心算法,会使用 C/C++ 处理,涉及数据处理的时候,为了安全和快速开发,会使用 Javascript 或 Python 等脚本语言实现数据分析处理.因此,开发者应该学习或掌握语言混合编程. C++ 和 Java 是主流的两种编程语言,但是现在整个网上对实

记录numpy和c++的混合编程

准备记录numpy和c++的混合编程 #include <boost/python.hpp> #include <numpy/ndarrayobject.h> namespace bp = boost::python; void reference_contiguous_array(PyObject* in, PyArrayObject* in_con, double* ptr, int& count) { in_con = PyArray_GETCONTIGUOUS((P

简单上手nodejs调用c++(c++和js的混合编程)

因为项目的原因,最近经常使用node.js搭RESTful接口. 性能还是很不错啦,感觉比Spring Boot之类的要快.而且在不错的性能之外,只要程序结构组织好,别让太多的回调把程序结构搞乱,整体开发效率比Java快的就太多了. 如果想进一步提高效率,使用c++来优化部分模块是不错的选择.尤其可贵的是nodejs对于同c++的混合编程支持的很好,个人感觉跟写Python的扩展模块处于同样的易用水平. 我们从Hello World开始: 首先要有一个空白的工作目录,在其中建立一个node包管理

extern &quot;C&quot; 的含义:????实现C++与C及其它语言的混合编程

C++中extern "C"的设立动机是实现C++与C及其它语言的混合编程. C++为了支持函数的重载,C++对全局函数的处理方式与C有明显的不同.对于函数void foo( int x, int y );该函数被C编译器编译后在符号库中的名字为_foo,而C++编译器则会产生像_foo_int_int之类的名字. extern是C/C++语言中表明函数和全局变量作用范围(可见性)的关键字,该关键字告诉编译器,其声明的函数和变量可以在本模块或其它模块中使用. 通常,在模块的头文件中对本

几种语言的CGI编程

为了了解PHP.JSP.ASP出现之前人们写网站的方法,洒家研究了一波CGI,使用C.Python.batch.shell script语言写了几个简单的网页. CGI即通用网关接口,指web服务器调用编程语言编写的程序的一个接口.洒家用的是Apache的CGI,QUERY_STRING.REMOTE_ADDR.REQUEST_URI等参数是通过环境变量传递给CGI程序的,请求主体(POST数据)作为CGI程序的标准输入(stdin),而CGI程序的标准输出(stdout)作为HTTP响应的部分