runtime系统的Cello

通过充当一个现代的、功能强大的runtime系统,Cello使许多以前在C中不切实际或笨拙的事情变得简单,例如:

通用数据结构

多态函数

接口/类型类

构造函数/析构函数

可选垃圾回收

例外情况

反思

而且,由于Cello与标准C无缝地协同工作,所以您可以获得其他所有的好处,例如出色的性能、强大的工具和广泛的库。

https://github.com/orangeduck/Cello

Examples

#include "Cello.h"

int main(int argc, char** argv) {

/* Stack objects are created using "$" */

var i0 = $(Int, 5);

var i1 = $(Int, 3);

var i2 = $(Int, 4);

/* Heap objects are created using "new" */

var items = new(Array, Int, i0, i1, i2);

/* Collections can be looped over */

foreach (item in items) {

print("Object %$ is of type %$\n",

item, type_of(item));

}

/* Heap objects destructed via Garbage Collection */

return 0;

}

#include "Cello.h"

int main(int argc, char** argv) {

/* Shorthand $ can be used for basic types */

var prices = new(Table, String, Int);

set(prices, $S("Apple"),  $I(12));

set(prices, $S("Banana"), $I( 6));

set(prices, $S("Pear"),   $I(55));

/* Tables also support iteration */

foreach (key in prices) {

var val = get(prices, key);

print("Price of %$ is %$\n", key, val);

}

return 0;

}

Articles

Learning Resources:

Articles about its creation and internal workings:

More Examples

#include "Cello.h"
 
int main(int argc, char** argv) {
 
  var items = new(Array, Int, 
    $I( 8), $I( 5), $I(20), 
    $I(15), $I(16), $I(98));
 
  /* Iterate over indices using "range" */
  foreach (i in range($I(len(items)))) {
    print("Item Range %i is %i\n", i, get(items, i));
  }
 
  /* Iterate over every other item with "slice" */ 
  foreach (item in slice(items, _, _, $I(2))) {
    print("Item Slice %i\n", item);
  }
  
  return 0;
}

#include "Cello.h"

/* Define a normal C structure */

struct Point {

float x, y;

};

/* Make it compatible with Cello */

var Point = Cello(Point);

int main(int argc, char** argv) {

/* Create on Stack or Heap */

var p0 = $(Point, 0.0, 1.0);

var p1 = new(Point, $(Point, 0.0, 2.0));

/* It can be shown, compared, hashed, etc...

**

** p0: <'Point' At 0x000000000022FC58>

** p1: <'Point' At 0x00000000004C7CC8>

** cmp: 1

** hash: 2849275892l

*/

print("p0: %$\np1: %$\ncmp: %i\nhash: %ul\n",

p0, p1, $I(cmp(p0, p1)), $I(hash(p0)));

/* And collected by the GC when out of scope */

return 0;

}

F.A.Q

为什么会有这种情况?

把Cello做为一个有趣的实验,看看C语言看起来像是被砍掉的极限。除了作为一个功能强大的库和工具箱外,对于那些想探索C语言的人来说,应该很有趣。

它是如何工作的?

建议阅读一个指针库来了解Cello是如何工作的。也可以浏览一下源代码,听说它是相当可读的。

它能用于产品吗?

最好先在业余爱好项目上试用Cello。Cello的目标是产品化之前试用,但因为它是一个怪物,它有着相当的奇特和陷阱,如果在团队中工作,或者在最后期限,那么C++等语言就有更好的工具、支持和社区。

有人用Cello吗?

有人已经尝试过它,据说,没有一个引人注目的项目使用它。Cello太大了,如果新的C项目想要便携和易于维护的话,它是一个很不错的依赖库。

最新文章

  1. flex总结
  2. ImageView属性
  3. 一次莽撞的行为:在phpmyadmin中修改MySQL root密码后无法操作数据库
  4. js中attr 与find 获取属性值,
  5. SQL Analysis Services MDX 查询超时 解决办法
  6. __new__
  7. 每日一语:What is he getting at?
  8. 【BZOJ 3545】【ONTAK 2010】Peaks &amp; 【BZOJ 3551】【ONTAK 2010】Peaks加强版 Kruskal重构树
  9. Spring-事物的隔离级别
  10. JavaScript中call、apply、bind、slice的使用
  11. Cocos2d 中的Sprite大小调整问题
  12. [C++知识点]2015.4.18
  13. HDU 4717The Moving Points warmup2 1002题(三分)
  14. Ubuntu通过使用PyCharm 进行调试 Odoo 8.0 可能出现的问题
  15. UNIX基础--用户和基本账户管理
  16. 转 vi 技巧和诀窍:令人刮目相看的 10 个超酷命令
  17. 字符串反转,例如&quot;abc&quot;反转&quot;cba&quot;
  18. Docker原生网络技术简介
  19. [Bayesian] “我是bayesian我怕谁”系列 - Exact Inference
  20. 关于丢失或者损坏/etc/fstab文件后的一些探讨

热门文章

  1. POJ 1386 欧拉路的判定
  2. POJ2553 强连通出度为0的应用
  3. Linux配置yum源(本地源和网络源)
  4. POJ1151基本的扫描线求面积
  5. Python爬虫之requests库的使用
  6. windows核心编程-第二章 Unicode
  7. Python学习笔记-StatsModels 统计回归(3)模型数据的准备
  8. PowerDesigner安装教程
  9. SQL Server 查看进程阻塞及处理
  10. Windows进程间通讯(IPC)----内存映射文件