日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

runtime系统的Cello

發布時間:2023/11/28 生活经验 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 runtime系统的Cello 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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:

Installation
Cello World
Quickstart
Common
Queries / Pitfalls

Articles about its creation and internal workings:

Best
Improvements of Cello 2.0
A Fat Pointer
Library
Cello vs C++
vs ObjC
Benchmarks
Garbage
Collection

More
Examples

#include “Cello.h”?int main(int argc, char** argv) {?? var items = new(Array, Int, ????$I( 8), $I( 5), I(20),I(20), ????I(20),????I(15), $I(16), I(98));/?Iterateoverindicesusing"range"?/foreach(iinrange(I(98));? ?/* Iterate over indices using "range" */ ?foreach (i in range(I(98));??/?Iterateoverindicesusing"range"?/?foreach(iinrange(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: %KaTeX parse error: Undefined control sequence: \np at position 1: \?n?p?1: %\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項目想要便攜和易于維護的話,它是一個很不錯的依賴庫。

總結

以上是生活随笔為你收集整理的runtime系统的Cello的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。