Created
June 7, 2012 15:29
-
-
Save nddrylliog/2889451 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <./list.h> | |
#include <sdk/lang/Exception.h> | |
#include <sdk/lang/BufferIterator.h> | |
#include <sdk/lang/System.h> | |
#include <sdk/lang/Character.h> | |
#include <sdk/lang/VarArgs.h> | |
#include <sdk/lang/string.h> | |
#include <sdk/lang/Iterators.h> | |
#include <sdk/lang/Memory.h> | |
#include <sdk/lang/Buffer.h> | |
#include <sdk/lang/Numbers.h> | |
#include <sdk/lang/Abstractions.h> | |
#include <sdk/lang/Format.h> | |
#include <sdk/lang/IO.h> | |
static lang_string__String* __strLit122; | |
static lang_string__String* __strLit120; | |
void list__List_get(list__List* this, uint8_t* __genericReturn2, lang_Numbers__Int index) { ((list__ListClass *)((lang_core__Object *)this)->class)->get((list__List*)this, __genericReturn2, index); } | |
void list__List_set(list__List* this, lang_Numbers__Int index, uint8_t* element) { return (void) ((list__ListClass *)((lang_core__Object *)this)->class)->set((list__List*)this, index, element); } | |
void list__List___defaults__(list__List* this) { return (void) ((lang_core__ObjectClass *)((lang_core__Object *)this)->class)->__defaults__((lang_core__Object*)this); } | |
list__List* list__List_new(lang_core__Class* X, lang_Numbers__SizeT size) { | |
list__List* this = ((list__List*) (lang_core__Class_alloc__class((lang_core__Class*) list__List_class()))); | |
this->X = X; | |
list__List___defaults__(this); | |
list__List_init((list__List*) this, size); | |
return this; | |
} | |
void list__List___load__() { | |
lang_core__Class___load__(); | |
} | |
void list__List_init(list__List* this, lang_Numbers__SizeT size) { | |
this->size = size; | |
this->data = (void*) lang_Memory__gc_malloc(this->X->size * size); | |
} | |
void list__List_get_impl(list__List* this, uint8_t* __genericReturn2, lang_Numbers__Int index) { | |
if (__genericReturn2) { | |
lang_Memory__memcpy(__genericReturn2, &(this->data[index * this->X->size]), this->X->size); | |
} | |
return; | |
} | |
void list__List_set_impl(list__List* this, lang_Numbers__Int index, uint8_t* element) { | |
lang_Memory__memcpy(&(this->data[index * this->X->size]), element, this->X->size); | |
} | |
void list__List___defaults___impl(list__List* this) { | |
lang_core__Class___defaults___impl((lang_core__Class*) this); | |
} | |
list__ListClass *list__List_class(){ | |
static int __done__ = 0; | |
static list__ListClass class = | |
{ | |
{ | |
{ | |
{ | |
{ NULL }, | |
(lang_Numbers__SizeT) 0, | |
(lang_Numbers__SizeT) 0, | |
(lang_string__String*) 0, | |
(lang_core__Class*) 0, | |
}, | |
(void*) list__List___defaults___impl, | |
(void*) lang_core__Object___destroy___impl, | |
(void*) list__List___load__, | |
}, | |
(void*) lang_core__Class_forCover, | |
}, | |
(void*) list__List_new, | |
(void*) list__List_get_impl, | |
(void*) list__List_set_impl, | |
}; | |
lang_core__Class *classPtr = (lang_core__Class *) &class; | |
if(!__done__++){ | |
classPtr->instanceSize = sizeof(list__List); | |
classPtr->size = sizeof(void*); | |
classPtr->super = (lang_core__Class*) lang_core__Object_class(); | |
classPtr->name = (void*) lang_string__makeStringLiteral("List", 4); | |
} | |
return &class; | |
} | |
void list__Letter___load__() { | |
lang_core__Class___load__(); | |
} | |
list__LetterClass *list__Letter_class(){ | |
static lang_core__Class* classPtr = NULL; | |
if (!classPtr) { | |
classPtr = (void*) lang_core__Class_forCover(sizeof(list__Letter), sizeof(list__Letter)); | |
classPtr->super = (lang_core__Class*) lang_core__Object_class(); | |
classPtr->name = (void*) lang_string__makeStringLiteral("Letter", 6); | |
} | |
return (void*) classPtr; | |
} | |
list__Letter list__List___specialized1_get(list__List___specialized1* this, lang_Numbers__Int index) { return (list__Letter) ((list__List___specialized1Class *)((lang_core__Object *)this)->class)->get((list__List___specialized1*)this, index); } | |
void list__List___specialized1_set(list__List___specialized1* this, lang_Numbers__Int index, list__Letter element) { return (void) ((list__List___specialized1Class *)((lang_core__Object *)this)->class)->set((list__List___specialized1*)this, index, element); } | |
void list__List___specialized1___defaults__(list__List___specialized1* this) { return (void) ((lang_core__ObjectClass *)((lang_core__Object *)this)->class)->__defaults__((lang_core__Object*)this); } | |
list__List___specialized1* list__List___specialized1_new(lang_Numbers__SizeT size) { | |
list__List___specialized1* this = ((list__List___specialized1*) (lang_core__Class_alloc__class((lang_core__Class*) list__List___specialized1_class()))); | |
this->X = (lang_core__Class*) list__Letter_class(); | |
list__List___specialized1___defaults__(this); | |
list__List___specialized1_init((list__List___specialized1*) this, size); | |
return this; | |
} | |
void list__List___specialized1___load__() { | |
lang_core__Class___load__(); | |
} | |
void list__List___specialized1_init(list__List___specialized1* this, lang_Numbers__SizeT size) { | |
this->size = size; | |
this->data = (void*) lang_Memory__gc_malloc(this->X->size * size); | |
} | |
list__Letter list__List___specialized1_get_impl(list__List___specialized1* this, lang_Numbers__Int index) { | |
return this->data[index]; | |
} | |
void list__List___specialized1_set_impl(list__List___specialized1* this, lang_Numbers__Int index, list__Letter element) { | |
lang_Memory__memcpy(&(this->data[index * this->X->size]), &(element), ((lang_core__Class*)list__Letter_class())->size); | |
} | |
void list__List___specialized1___defaults___impl(list__List___specialized1* this) { | |
lang_core__Class___defaults___impl((lang_core__Class*) this); | |
} | |
list__List___specialized1Class *list__List___specialized1_class(){ | |
static int __done__ = 0; | |
static list__List___specialized1Class class = | |
{ | |
{ | |
{ | |
{ | |
{ NULL }, | |
(lang_Numbers__SizeT) 0, | |
(lang_Numbers__SizeT) 0, | |
(lang_string__String*) 0, | |
(lang_core__Class*) 0, | |
}, | |
(void*) list__List___specialized1___defaults___impl, | |
(void*) lang_core__Object___destroy___impl, | |
(void*) list__List___specialized1___load__, | |
}, | |
(void*) lang_core__Class_forCover, | |
}, | |
(void*) list__List___specialized1_new, | |
(void*) list__List___specialized1_get_impl, | |
(void*) list__List___specialized1_set_impl, | |
}; | |
lang_core__Class *classPtr = (lang_core__Class *) &class; | |
if(!__done__++){ | |
classPtr->instanceSize = sizeof(list__List___specialized1); | |
classPtr->size = sizeof(void*); | |
classPtr->super = (lang_core__Class*) lang_core__Object_class(); | |
classPtr->name = (void*) lang_string__makeStringLiteral("List___specialized1", 19); | |
} | |
return &class; | |
} | |
void list_load() { | |
static int __done__ = 0; | |
if (!__done__++){ | |
lang_Exception_load(); | |
lang_BufferIterator_load(); | |
lang_System_load(); | |
lang_Character_load(); | |
lang_VarArgs_load(); | |
lang_core_load(); | |
lang_string_load(); | |
lang_Iterators_load(); | |
lang_Memory_load(); | |
lang_Buffer_load(); | |
lang_Numbers_load(); | |
lang_Abstractions_load(); | |
lang_Format_load(); | |
lang_IO_load(); | |
list__List___load__(); | |
list__Letter___load__(); | |
list__List___specialized1___load__(); | |
__strLit122 = (void*) lang_string__makeStringLiteral("%c", 2); | |
__strLit120 = (void*) lang_string__makeStringLiteral("%c", 2); | |
} | |
} | |
void list__test1() { | |
list__List* l = list__List_new((lang_core__Class*)lang_Character__Char_class(), 3); | |
lang_Character__Char __genArg117 = 'f'; | |
list__List_set(l, 0, (uint8_t*) &(__genArg117)); | |
lang_Character__Char __genArg118 = 'a'; | |
list__List_set(l, 1, (uint8_t*) &(__genArg118)); | |
lang_Character__Char __genArg119 = 'q'; | |
list__List_set(l, 2, (uint8_t*) &(__genArg119)); | |
{ | |
lang_Numbers__Int i; | |
for (i = 0; i < l->size; i++) { | |
lang_Character__Char __genCall121; | |
lang_IO__printf(lang_string____OP_AS_String__Char__star(__strLit120), (list__List_get(l, (uint8_t*) &(__genCall121), i), __genCall121)); | |
} | |
} | |
lang_IO__println(); | |
} | |
void list__test2() { | |
list__List___specialized1* l = list__List___specialized1_new(3); | |
list__List___specialized1_set(l, 0, ((list__Letter) ('f'))); | |
list__List___specialized1_set(l, 1, ((list__Letter) ('a'))); | |
list__List___specialized1_set(l, 2, ((list__Letter) ('q'))); | |
{ | |
lang_Numbers__Int i; | |
for (i = 0; i < l->size; i++) { | |
lang_IO__printf(lang_string____OP_AS_String__Char__star(__strLit122), list__List___specialized1_get(l, i)); | |
} | |
} | |
lang_IO__println(); | |
} | |
lang_Numbers__Int main() { | |
GC_INIT(); | |
list_load(); | |
list__test1(); | |
list__test2(); | |
return ((lang_Numbers__Int) (0)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List: class <X> { | |
data: X* | |
size: SizeT | |
init: func (=size) { | |
data = gc_malloc(X size * size) | |
} | |
get: func (index: Int) -> X { | |
data[index] | |
} | |
set: func (index: Int, element: X) { | |
data[index] = element | |
} | |
} | |
Letter: cover from Char { } | |
#specialize List<Letter> | |
test1: func { | |
l := List<Char> new(3) | |
l set(0, 'f') | |
l set(1, 'a') | |
l set(2, 'q') | |
for (i in 0..l size) { | |
printf("%c", l get(i)) | |
} | |
println() | |
} | |
test2: func { | |
l := List<Letter> new(3) | |
l set(0, 'f' as Letter) | |
l set(1, 'a' as Letter) | |
l set(2, 'q' as Letter) | |
for (i in 0..l size) { | |
printf("%c", l get(i)) | |
} | |
println() | |
} | |
main: func { | |
test1() | |
test2() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment