Chinaunix首页 | 论坛 | 博客
  • 博客访问: 34432
  • 博文数量: 18
  • 博客积分: 485
  • 博客等级: 下士
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-28 11:55
文章分类
文章存档

2011年(18)

我的朋友

分类: Python/Ruby

2011-05-13 11:12:11

Overview

Squirrel is a high level imperative, object-oriented programming language, designed to be a light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games. Although Squirrel offers a wide range of features like:

  • Open Source
  • dynamic typing
  • delegation
  • classes & inheritance
  • higher order functions
  • lexical scoping
  • generators
  • cooperative threads(coroutines) 
  • tail recursion
  • exception handling
  • automatic memory management (CPU bursts free; mixed approach ref counting/GC)
  • both compiler and virtual machine fit together in about 7k lines of C++ code.
  • optional 16bits characters strings

Squirrel is inspired by languages like Python,Javascript and expecially Lua(The API is very similar and the table code is based on the Lua one)


What Does it look like?
squirrel's syntax is similar to C/C++/Java etc... but the language has a very dynamic nature like python/Lua etc...

  1. local table = {
  2.     a = "10"
  3.     subtable = {
  4.         array = [1,2,3]
  5.     },
  6.     [10 + 123] = "expression index"
  7. }
  8.  
  9. local array=[ 1, 2, 3, { a = 10, b = "string" } ];
  10.  
  11. foreach (i,val in array)
  12. {
  13.     ::print("the type of val is"+typeof val);
  14. }
  15.  
  16. /////////////////////////////////////////////
  17.  
  18. class Entity
  19. {    
  20.     constructor(etype,entityname)
  21.     {
  22.         name = entityname;
  23.         type = etype;
  24.     }
  25.                                     
  26.     x = 0;
  27.     y = 0;
  28.     z = 0;
  29.     name = null;
  30.     type = null;
  31. }
  32.  
  33. function Entity::MoveTo(newx,newy,newz)
  34. {
  35.     x = newx;
  36.     y = newy;
  37.     z = newz;
  38. }
  39.  
  40. class Player extends Entity {
  41.     constructor(entityname)
  42.     {
  43.         base.constructor("Player",entityname)
  44.     }
  45.     function DoDomething()
  46.     {
  47.         ::print("something");
  48.     }
  49.     
  50. }
  51.  
  52. local newplayer = Player("da playar");
  53.  
  54. newplayer.MoveTo(100,200,300);

Development state
    The current stable release is 3.0
    The project has been compiled and run on Windows(x86 & x64), Linux(x86 & x64) and Solaris(x86 & x64).
    Has been tested with the following compilers:

    MS Visual C++ 6.0,7.0,7.1,8.0,9.0 and 10.0(x86 & x64)
    MinGW gcc 3.2 (mingw special 20020817-1)
    Cygwin gcc 3.2
    Linux gcc 3.x Linux gcc 4.x Solaris gcc 3.x


    The documentation has to be improved.

    I'd like to have some feed back and maybe help to design/port/test it.


Work in Progress

In the next release(3.1 stable):

  • api impovements
  • performance tuning
  • additional documentation


Documentation
Squirrel 3.x

Squirrel 3.0 reference manual(//)

Squirrel 3.0 Standard Libraries manual(//)

both manuals are included in the language distribution


Squirrel 2.x

Squirrel 2.0 reference manual(//)

Squirrel 2.0 Standard Libraries manual(//)

both manuals are included in the language distribution


Download
stable release

You can download Squirrel 3.0 stable
Released March 13, 2011.

older 2.x stable release

You can download Squirrel 2.2.4 stable
Released November 15, 2009.

Author

My name is Alberto Demichelis if you want to know more about me, this is

--------------------------------------------------------------------------------

中文介绍
  Squirrel是一种较新的程序设计语言,它从著名的LUA语言继承了很多特性,适用的范围也与LUA语言相似。
   Squirrel的作者是意大利人Alberto Demichelis,SQUIRREL开发的本意是用于替代LUA,LUA的很多语法与C/C++ 不一致,C/C++程序员写脚本时,容易犯错误,而SQUIRREL语法与C/C++很相似,因此Squirrel更适合C/C++ 程序员。
   Squirrel是一种动态语言,它有一个编译器和虚拟机,代码会被动态编译成字节码,然后在 虚拟机上执行。当然,这种编译比C/C++或者Java的编译要简单很多,它的虚拟机也不会有JVM这样“底层”,Squirrel的虚拟机更像是一个 “函数执行队列”,这个虚拟机是建立在标准libc基础上的(也就是说标准C函数在这个虚拟机中是元操作,而JVM是建立在汇编语言基础上的)。
   Squirrel在设计上就是要做到嵌入C/C++程序,因此,Squirrel虚拟机可以与 C/C++工作在一个进程/线程当中,通过虚拟机的接口,C/C++的数据可以被嵌入的Squirrel代码访问,反之Squirrel的代码和数据也可 以被C/C++完全控制。
   从语言结构上看,Squirrel与Lua一脉相承,Squirrel与Lua的基础都是广义表(或者说是一颗多叉树),Hash算法在这个广义表中起到一个关键的作用。
   Squirrel代码和数据都是组织在一个广义表当中的。数据、函数、类(Lua不支持OO,Squirrel支持有限的OO)都是广义表的一个值,值都是采用<名称,值>的方式存储的,通过对名称的Hash,可以很方便的找到值。
   Squirrel比Lua更好的支持OO,Squirrel可以定义类,允许类继承,能够自动 执行构造(constructor函数),而Lua只能通过Table来模拟类。更关键的一点,Squirrel允许类产生实例(instance),每 个实例拥有自己的存储空间,在这点上,比Lua的模拟类明显好用。
   Squirrel支持在每个实例上设置一个Userpoint,这个特性非常有利与与 C++Object的接口,一个Squirrel类可以的作为一个C++ class的影子运行,我们只需要在Squirrel上实现C++class的接口,通过Squirrel的Userpoint,即可操控这个C++ Object。
   值得关注的是Squirrel的执行速度,执行一个10000元素的数组创建及遍历,其速度大约是C++的1/4,比Lua快20%。
   Squirrel的保留字与C++几乎一致,但Squirrel没有指针,内存由虚拟机管理, 不需要手工申请和释放,所以没有new和delete关键字。Squirrel是弱类型的,所以也就没有char、float、int、double等关 键字,值得注意到是Squirrel不支持double(Squirrel 3.0支持使用double代替float),其浮点数内部是float,这可能与Squirrel主要为游戏设计有关。
   Squirrel新增了一些关键字,主要有local、typeof、instanceof、 resum、yield、delegate、parent等(其中delegate、 parent关键字在Squirrel3.0Alpha版中似乎有变化),resum、yield用于Squirrel的“协程”,可以理解为非抢先式的 内部线程(Squirrel虚拟机是单线程的,一个虚拟机内部不支持系统的线程,这和Lua很相似)。
   值得注意的是local关键字,Squirrel中的变量是需要定义的,和C++一样,你可以在程序的任何地方定义,但定义的时候必须使用local关键字。使用local表明变量在堆栈里创建,离开函数才会自动销毁。
   Squirrel循环控制语句增加了foreach循环,而且这个foreach不像Lua一 样需要什么“闭包”,可以很简单的使用,例如foreach(local i in arrayVar){},这完成对一个数组的遍历,foreach(local key,value in tableVar){}, 这完成对一个表达遍历。

阅读(1143) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~