Swapped pointers to the other side for types to prevent ambiguity, i.e. *int instead of int*
This commit is contained in:
@@ -2,7 +2,7 @@ Goal = translation_unit ;
|
||||
translation_unit = WS unorderd_list_part WS ;
|
||||
unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def line_end WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement line_end WS unorderd_list_part | import | function | type_def line_end | if_comp | simple_passthrough | declaration_statement line_end ;
|
||||
|
||||
type = type WS "\*" | "void" | "int" | "float" | "double" | "char" | scoped_identifier | scoped_identifier WS template_inst | function_type ;
|
||||
type = "\*" WS type | "void" | "int" | "float" | "double" | "char" | scoped_identifier | scoped_identifier WS template_inst | function_type ;
|
||||
function_type = "fun" WS "\(" WS opt_type_list WS "\)" WS ":" WS type ;
|
||||
dec_type = ":" WS type ;
|
||||
|
||||
|
||||
@@ -1137,11 +1137,11 @@ void ASTTransformation::unifyType(NodeTree<Symbol> *syntaxType, Type type, std::
|
||||
// doing a template member function of a templated object
|
||||
} else {
|
||||
// go down one in our pointer
|
||||
if (children.back()->getDataRef()->getValue() == "*") {
|
||||
if (children.front()->getDataRef()->getValue() == "*") {
|
||||
// gotta be a better way to do this
|
||||
Type* clonedType = type.clone();
|
||||
clonedType->decreaseIndirection();
|
||||
unifyType(children.front(), *clonedType, templateTypeMap, typeMap);
|
||||
unifyType(children.back(), *clonedType, templateTypeMap, typeMap);
|
||||
delete clonedType;
|
||||
return;
|
||||
}
|
||||
@@ -1449,11 +1449,13 @@ Type* ASTTransformation::typeFromTypeNode(NodeTree<Symbol>* typeNode, NodeTree<A
|
||||
NodeTree<ASTData>* typeDefinition = NULL;
|
||||
std::set<std::string> traits;
|
||||
// To counter this, for every indirection we step down a level
|
||||
while (typeIn[typeIn.size() - indirection - 1] == '*') {
|
||||
//while (typeIn[indirection] == '*') {
|
||||
//since fun(*T):int gets transformed to *T:int, the text based way doesn't work anymore
|
||||
while (typeNode->getChildren().size() && typeNode->getChildren().front()->getDataRef()->getValue() == "*") {
|
||||
indirection++;
|
||||
typeNode = typeNode->getChildren()[0];
|
||||
typeNode = typeNode->getChildren().back();
|
||||
};
|
||||
std::string edited = strSlice(typeIn, 0, -(indirection + 1));
|
||||
std::string edited = strSlice(typeIn, indirection, -1);
|
||||
if (edited == "void")
|
||||
baseType = void_type;
|
||||
else if (edited == "bool")
|
||||
|
||||
@@ -52,11 +52,11 @@ obj grammer (Object) {
|
||||
var rules: vector::vector<rule>
|
||||
var regexs: set::set<regex::regex>
|
||||
|
||||
fun construct(): grammer* {
|
||||
fun construct(): *grammer {
|
||||
rules.construct()
|
||||
regexs.construct()
|
||||
}
|
||||
fun copy_construct(old: grammer*) {
|
||||
fun copy_construct(old: *grammer) {
|
||||
rules.copy_construct(&old->rules)
|
||||
regexs.copy_construct(&old->regexs)
|
||||
}
|
||||
@@ -91,13 +91,13 @@ obj rule (Object) {
|
||||
var position: int
|
||||
var lookahead: set::set<symbol::symbol>
|
||||
|
||||
fun construct(): rule* {
|
||||
fun construct(): *rule {
|
||||
lhs.construct()
|
||||
rhs.construct()
|
||||
position = 0
|
||||
lookahead.construct()
|
||||
}
|
||||
fun copy_construct(other: rule*) {
|
||||
fun copy_construct(other: *rule) {
|
||||
lhs.copy_construct(&other->lhs)
|
||||
rhs.copy_construct(&other->rhs)
|
||||
position = other->position
|
||||
|
||||
@@ -14,7 +14,7 @@ fun println<T>(toPrint: T) : void {
|
||||
print("\n")
|
||||
}
|
||||
|
||||
fun print(toPrint: char*) : void {
|
||||
fun print(toPrint: *char) : void {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(toPrint = toPrint::) """
|
||||
printf("%s", toPrint);
|
||||
@@ -77,7 +77,7 @@ fun print(toPrint: double) : void{
|
||||
fun read_file(path: string::string): string::string {
|
||||
var char_path = path.toCharArray()
|
||||
defer delete(char_path)
|
||||
var data: char*
|
||||
var data: *char
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(char_path = char_path:data = data:) """
|
||||
FILE *fp = fopen(char_path, "r");
|
||||
|
||||
@@ -8,7 +8,7 @@ obj lexer (Object) {
|
||||
var regs: vector::vector<regex::regex>
|
||||
var input: string::string
|
||||
var position: int
|
||||
fun construct(): lexer* {
|
||||
fun construct(): *lexer {
|
||||
regs.construct()
|
||||
input.construct()
|
||||
position = 0
|
||||
@@ -18,7 +18,7 @@ obj lexer (Object) {
|
||||
regs.destruct()
|
||||
input.destruct()
|
||||
}
|
||||
fun copy_construct(old: lexer*) {
|
||||
fun copy_construct(old: *lexer) {
|
||||
regs.copy_construct(&old->regs)
|
||||
input.copy_construct(&old->input)
|
||||
position = old->position
|
||||
@@ -30,7 +30,7 @@ obj lexer (Object) {
|
||||
fun add_regex(newOne: regex::regex) {
|
||||
regs.add(newOne)
|
||||
}
|
||||
fun add_regex(newOne: char*) {
|
||||
fun add_regex(newOne: *char) {
|
||||
regs.add(regex::regex(newOne))
|
||||
}
|
||||
fun set_input(in: string::string) {
|
||||
|
||||
@@ -19,7 +19,7 @@ obj map<T,U> (Object) {
|
||||
keys.construct()
|
||||
values.construct()
|
||||
}
|
||||
fun copy_construct(old: map<T,U>*) {
|
||||
fun copy_construct(old: *map<T,U>) {
|
||||
keys.copy_construct(&old->keys)
|
||||
values.copy_construct(&old->values)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import vector:*;
|
||||
import io:*;
|
||||
|
||||
typedef matrix (Object) {
|
||||
obj matrix (Object) {
|
||||
var data: vector<double>;
|
||||
var rows: int;
|
||||
var cols: int;
|
||||
@@ -12,7 +12,7 @@ typedef matrix (Object) {
|
||||
|
||||
//Constructor with no arguments
|
||||
//No matrix is made
|
||||
fun construct(): matrix* {
|
||||
fun construct(): *matrix {
|
||||
rows = 0;
|
||||
cols = 0;
|
||||
data.construct();
|
||||
@@ -21,7 +21,7 @@ typedef matrix (Object) {
|
||||
|
||||
//Constructor with single argument
|
||||
//Creates an N x N matrix
|
||||
fun construct(size: int): matrix* {
|
||||
fun construct(size: int): *matrix {
|
||||
rows = size;
|
||||
cols = size;
|
||||
data.construct(rows*cols);
|
||||
@@ -30,7 +30,7 @@ typedef matrix (Object) {
|
||||
|
||||
//Constructor with two arguments
|
||||
//Creates an N x M matrix
|
||||
fun construct(r: int, c: int): matrix* {
|
||||
fun construct(r: int, c: int): *matrix {
|
||||
rows = r;
|
||||
cols = c;
|
||||
data.construct(rows*cols);
|
||||
@@ -144,23 +144,3 @@ typedef matrix (Object) {
|
||||
|
||||
};//end Matrix class
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ __if_comp__ __C__ simple_passthrough """
|
||||
|
||||
/* we have a template versions so we don't have to cast (because we don't have that yet) */
|
||||
|
||||
fun malloc<T>(size: int): T* {
|
||||
var memPtr: T*;
|
||||
fun malloc<T>(size: int): *T {
|
||||
var memPtr: *T;
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough( size = size, memPtr = memPtr : memPtr = memPtr :) """
|
||||
memPtr = malloc(size);
|
||||
@@ -16,7 +16,7 @@ fun malloc<T>(size: int): T* {
|
||||
return memPtr;
|
||||
}
|
||||
|
||||
fun free<T>(memPtr: T*): void {
|
||||
fun free<T>(memPtr: *T): void {
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(memPtr = memPtr ::) """
|
||||
free(memPtr);
|
||||
@@ -25,7 +25,7 @@ fun free<T>(memPtr: T*): void {
|
||||
}
|
||||
|
||||
fun sizeof<T>(): int {
|
||||
var testObj: T*;
|
||||
var testObj: *T;
|
||||
var result: int;
|
||||
__if_comp__ __C__ {
|
||||
simple_passthrough(testObj = testObj : result = result:) """
|
||||
@@ -35,21 +35,21 @@ fun sizeof<T>(): int {
|
||||
return result;
|
||||
}
|
||||
|
||||
fun new<T>(count: int): T* {
|
||||
fun new<T>(count: int): *T {
|
||||
return malloc<T>( sizeof<T>() * count );
|
||||
}
|
||||
|
||||
fun new<T>(): T* {
|
||||
fun new<T>(): *T {
|
||||
return new<T>(1);
|
||||
}
|
||||
|
||||
/* We specilize on the trait Object to decide on whether or not the destructor should be called */
|
||||
fun delete<T>(toDelete: T*, itemCount: int): void {
|
||||
fun delete<T>(toDelete: *T, itemCount: int): void {
|
||||
delete<T>(toDelete);
|
||||
}
|
||||
|
||||
/* Calling this with itemCount = 0 allows you to delete destructable objects without calling their destructors. */
|
||||
fun delete<T(Object)>(toDelete: T*, itemCount: int): void {
|
||||
fun delete<T(Object)>(toDelete: *T, itemCount: int): void {
|
||||
// start at one because the actual delete will call the destructor of the first one as it
|
||||
// finishes the pointer
|
||||
for (var i: int = 0; i < itemCount; i++;)
|
||||
@@ -59,50 +59,50 @@ fun delete<T(Object)>(toDelete: T*, itemCount: int): void {
|
||||
}
|
||||
|
||||
/* We specilize on the trait Object to decide on whether or not the destructor should be called */
|
||||
fun delete<T>(toDelete: T*): void {
|
||||
fun delete<T>(toDelete: *T): void {
|
||||
free<T>(toDelete);
|
||||
}
|
||||
|
||||
fun delete<T(Object)>(toDelete: T*): void {
|
||||
fun delete<T(Object)>(toDelete: *T): void {
|
||||
toDelete->destruct();
|
||||
free<T>(toDelete);
|
||||
}
|
||||
|
||||
// a wrapper for construct if it has the Object trait
|
||||
fun maybe_construct<T>(it:T*):T* {
|
||||
fun maybe_construct<T>(it:*T):*T {
|
||||
return it
|
||||
}
|
||||
|
||||
fun maybe_construct<T(Object)>(it:T*):T* {
|
||||
fun maybe_construct<T(Object)>(it:*T):*T {
|
||||
return it->construct()
|
||||
}
|
||||
|
||||
|
||||
// a wrapper for copy constructing if it has the Object trait
|
||||
fun maybe_copy_construct<T>(to:T*, from:T*):void {
|
||||
fun maybe_copy_construct<T>(to:*T, from:*T):void {
|
||||
*to = *from
|
||||
}
|
||||
|
||||
fun maybe_copy_construct<T(Object)>(to:T*, from:T*):void {
|
||||
fun maybe_copy_construct<T(Object)>(to:*T, from:*T):void {
|
||||
to->copy_construct(from)
|
||||
}
|
||||
|
||||
// a wrapper for destruct if it has the Object trait
|
||||
fun maybe_destruct<T>(it:T*):void {}
|
||||
fun maybe_destruct<T>(it:*T):void {}
|
||||
|
||||
fun maybe_destruct<T(Object)>(it:T*):void {
|
||||
fun maybe_destruct<T(Object)>(it:*T):void {
|
||||
it->destruct()
|
||||
}
|
||||
|
||||
// a function that allows the safe deletion of recursive and complicated data structures
|
||||
fun safe_recursive_delete<T>(first: T*, addingFunc: fun(T*): set::set<T*>) {
|
||||
var toDelete = set::set<T*>()
|
||||
fun safe_recursive_delete<T>(first: *T, addingFunc: fun(*T): set::set<*T>) {
|
||||
var toDelete = set::set<*T>()
|
||||
var next = set::set(first)
|
||||
while (toDelete != next) {
|
||||
toDelete = next
|
||||
toDelete.for_each( fun(it: T*) next.add(addingFunc(it)); )
|
||||
toDelete.for_each( fun(it: *T) next.add(addingFunc(it)); )
|
||||
}
|
||||
toDelete.for_each( fun(it: T*) delete(it); )
|
||||
toDelete.for_each( fun(it: *T) delete(it); )
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import set
|
||||
import util
|
||||
import conversions
|
||||
|
||||
fun regex(in: char*):regex {
|
||||
fun regex(in: *char):regex {
|
||||
return regex(string::string(in))
|
||||
}
|
||||
fun regex(in: string::string):regex {
|
||||
@@ -16,46 +16,46 @@ fun regex(in: string::string):regex {
|
||||
|
||||
obj regexState (Object) {
|
||||
var character: char
|
||||
var next_states: vector::vector<regexState*>
|
||||
fun construct(charIn:char): regexState* {
|
||||
var next_states: vector::vector<*regexState>
|
||||
fun construct(charIn:char): *regexState {
|
||||
character = charIn
|
||||
next_states.construct()
|
||||
return this
|
||||
}
|
||||
fun construct(): regexState* {
|
||||
fun construct(): *regexState {
|
||||
return construct(conversions::to_char(0))
|
||||
}
|
||||
fun copy_construct(old:regexState*): void {
|
||||
fun copy_construct(old:*regexState): void {
|
||||
character = old->character
|
||||
next_states.copy_construct(&old->next_states)
|
||||
}
|
||||
fun destruct():void {
|
||||
next_states.destruct()
|
||||
}
|
||||
fun match(input: char): vector::vector<regexState*> {
|
||||
return next_states.filter(fun(it:regexState*):bool { return it->character == input; })
|
||||
fun match(input: char): vector::vector<*regexState> {
|
||||
return next_states.filter(fun(it:*regexState):bool { return it->character == input; })
|
||||
}
|
||||
fun is_end():bool {
|
||||
return next_states.any_true(fun(state: regexState*):bool { return state->character == 1; })
|
||||
return next_states.any_true(fun(state: *regexState):bool { return state->character == 1; })
|
||||
}
|
||||
}
|
||||
|
||||
obj regex (Object) {
|
||||
var regexString: string::string
|
||||
var begin: regexState*
|
||||
var begin: *regexState
|
||||
|
||||
fun construct(regexStringIn: string::string): regex* {
|
||||
fun construct(regexStringIn: string::string): *regex {
|
||||
regexString.copy_construct(®exStringIn)
|
||||
|
||||
var beginningAndEnd = compile(regexStringIn)
|
||||
// init our begin, and the end state as the next state of each end
|
||||
begin = beginningAndEnd.first
|
||||
var end = mem::new<regexState>()->construct(conversions::to_char(1))
|
||||
beginningAndEnd.second.for_each(fun(it: regexState*): void { it->next_states.add(end); })
|
||||
beginningAndEnd.second.for_each(fun(it: *regexState): void { it->next_states.add(end); })
|
||||
return this
|
||||
}
|
||||
|
||||
fun copy_construct(old:regex*):void {
|
||||
fun copy_construct(old:*regex):void {
|
||||
//begin = old->begin
|
||||
//regexString.copy_construct(&old->regexString)
|
||||
construct(old->regexString)
|
||||
@@ -63,7 +63,7 @@ obj regex (Object) {
|
||||
|
||||
fun destruct():void {
|
||||
regexString.destruct()
|
||||
mem::safe_recursive_delete(begin, fun(it: regexState*): set::set<regexState*> { return set::from_vector(it->next_states); } )
|
||||
mem::safe_recursive_delete(begin, fun(it: *regexState): set::set<*regexState> { return set::from_vector(it->next_states); } )
|
||||
}
|
||||
|
||||
fun operator==(other: regex):bool {
|
||||
@@ -75,10 +75,10 @@ obj regex (Object) {
|
||||
construct(other.regexString)
|
||||
}
|
||||
|
||||
fun compile(regex_string: string::string): util::pair<regexState*, vector::vector<regexState*>> {
|
||||
fun compile(regex_string: string::string): util::pair<*regexState, vector::vector<*regexState>> {
|
||||
var first = mem::new<regexState>()->construct()
|
||||
var previous_begin = vector::vector<regexState*>()
|
||||
var previous_end = vector::vector<regexState*>()
|
||||
var previous_begin = vector::vector<*regexState>()
|
||||
var previous_end = vector::vector<*regexState>()
|
||||
var current_begin = vector::vector(first)
|
||||
var current_end = vector::vector(first)
|
||||
var alternating = false
|
||||
@@ -115,11 +115,11 @@ obj regex (Object) {
|
||||
i = perenEnd-1
|
||||
|
||||
if (alternating) {
|
||||
previous_end.for_each(fun(it: regexState*):void { it->next_states.add_all(innerBeginEnd.first->next_states); } )
|
||||
previous_end.for_each(fun(it: *regexState):void { it->next_states.add_all(innerBeginEnd.first->next_states); } )
|
||||
current_begin.add_all(innerBeginEnd.first->next_states)
|
||||
current_end.add_all(innerBeginEnd.second)
|
||||
} else {
|
||||
current_end.for_each(fun(it: regexState*):void { it->next_states.add_all(innerBeginEnd.first->next_states); } )
|
||||
current_end.for_each(fun(it: *regexState):void { it->next_states.add_all(innerBeginEnd.first->next_states); } )
|
||||
previous_begin = current_begin
|
||||
previous_end = current_end
|
||||
current_begin = innerBeginEnd.first->next_states
|
||||
@@ -133,11 +133,11 @@ obj regex (Object) {
|
||||
} else {
|
||||
var next = mem::new<regexState>()->construct(regex_string[i])
|
||||
if (alternating) {
|
||||
previous_end.for_each(fun(it: regexState*):void { it->next_states.add(next); })
|
||||
previous_end.for_each(fun(it: *regexState):void { it->next_states.add(next); })
|
||||
current_begin.add(next)
|
||||
current_end.add(next)
|
||||
} else {
|
||||
current_end.for_each(fun(it: regexState*):void { it->next_states.add(next); })
|
||||
current_end.for_each(fun(it: *regexState):void { it->next_states.add(next); })
|
||||
previous_begin = current_begin
|
||||
previous_end = current_end
|
||||
current_begin = vector::vector(next)
|
||||
@@ -151,19 +151,19 @@ obj regex (Object) {
|
||||
return beginAndEnd
|
||||
}
|
||||
|
||||
fun long_match(to_match: char*): int { return long_match(string::string(to_match)); }
|
||||
fun long_match(to_match: *char): int { return long_match(string::string(to_match)); }
|
||||
fun long_match(to_match: string::string): int {
|
||||
var next = vector::vector(begin)
|
||||
var longest = -1
|
||||
for (var i = 0; i < to_match.length(); i++;) {
|
||||
if (next.size == 0)
|
||||
return longest
|
||||
if (next.any_true(fun(state: regexState*):bool { return state->is_end(); }))
|
||||
if (next.any_true(fun(state: *regexState):bool { return state->is_end(); }))
|
||||
longest = i
|
||||
//next = next.flatten_map<regexState*>(fun(state: regexState*): vector::vector<regexState*> { return state->match(to_match[i]); })
|
||||
next = next.flatten_map(fun(state: regexState*): vector::vector<regexState*> { return state->match(to_match[i]); })
|
||||
//next = next.flatten_map<*regexState>(fun(state: *regexState): vector::vector<*regexState> { return state->match(to_match[i]); })
|
||||
next = next.flatten_map(fun(state: *regexState): vector::vector<*regexState> { return state->match(to_match[i]); })
|
||||
}
|
||||
if (next.any_true(fun(state: regexState*):bool { return state->is_end(); }))
|
||||
if (next.any_true(fun(state: *regexState):bool { return state->is_end(); }))
|
||||
return to_match.length()
|
||||
return longest
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ obj set<T> (Object) {
|
||||
fun construct() {
|
||||
data.construct()
|
||||
}
|
||||
fun copy_construct(old: set<T>*) {
|
||||
fun copy_construct(old: *set<T>) {
|
||||
data.copy_construct(&old->data)
|
||||
}
|
||||
fun operator=(rhs: set<T>) {
|
||||
|
||||
@@ -2,18 +2,18 @@ import vector
|
||||
import util
|
||||
import mem
|
||||
|
||||
fun string(in:char*):string {
|
||||
fun string(in:*char):string {
|
||||
var out:string = in
|
||||
return out
|
||||
}
|
||||
|
||||
obj string (Object) {
|
||||
var data: vector::vector<char>;
|
||||
fun construct(): string* {
|
||||
fun construct(): *string {
|
||||
data.construct();
|
||||
return this;
|
||||
}
|
||||
fun construct(str: char*): string* {
|
||||
fun construct(str: *char): *string {
|
||||
data.construct();
|
||||
while(*str) {
|
||||
data.addEnd(*str);
|
||||
@@ -22,23 +22,23 @@ obj string (Object) {
|
||||
// no null terminator
|
||||
return this;
|
||||
}
|
||||
fun construct(vec: vector::vector<char>): string* {
|
||||
fun construct(vec: vector::vector<char>): *string {
|
||||
data.copy_construct(&vec);
|
||||
return this;
|
||||
}
|
||||
fun construct(str: string): string* {
|
||||
fun construct(str: string): *string {
|
||||
return construct(str.data);
|
||||
}
|
||||
|
||||
fun copy_construct(old: string*): void {
|
||||
fun copy_construct(old: *string): void {
|
||||
data.copy_construct(&old->data)
|
||||
}
|
||||
|
||||
fun copy_construct(old: char**): void {
|
||||
fun copy_construct(old: **char): void {
|
||||
construct(*old)
|
||||
}
|
||||
|
||||
fun operator=(str: char*): void {
|
||||
fun operator=(str: *char): void {
|
||||
destruct();
|
||||
construct(str)
|
||||
}
|
||||
@@ -69,7 +69,7 @@ obj string (Object) {
|
||||
return length() == other.length() && !util::range(length()).any_true(fun(i: int):bool { return data[i] != other[i]; } )
|
||||
}
|
||||
|
||||
fun operator+(str: char*): string {
|
||||
fun operator+(str: *char): string {
|
||||
var newStr.construct(str):string
|
||||
var ret.construct(data + newStr.data):string
|
||||
return ret
|
||||
@@ -85,7 +85,7 @@ obj string (Object) {
|
||||
data += character
|
||||
}
|
||||
|
||||
fun operator+=(str: char*): void {
|
||||
fun operator+=(str: *char): void {
|
||||
var newStr.construct(str):string
|
||||
data += newStr.data
|
||||
}
|
||||
@@ -95,8 +95,8 @@ obj string (Object) {
|
||||
data += newStr.data
|
||||
}
|
||||
|
||||
fun toCharArray(): char* {
|
||||
var out: char* = mem::new<char>(data.size+1);
|
||||
fun toCharArray(): *char {
|
||||
var out: *char = mem::new<char>(data.size+1);
|
||||
for (var i: int = 0; i < data.size; i++;)
|
||||
out[i] = data.get(i);
|
||||
// null terminator
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import string
|
||||
|
||||
fun symbol(nameIn: char*, terminalIn: bool): symbol {
|
||||
fun symbol(nameIn: *char, terminalIn: bool): symbol {
|
||||
var toRet.construct(string::string(nameIn), terminalIn, string::string("no_value")): symbol
|
||||
return toRet
|
||||
}
|
||||
@@ -10,7 +10,7 @@ fun symbol(nameIn: string::string, terminalIn: bool): symbol {
|
||||
return toRet
|
||||
}
|
||||
|
||||
fun symbol(nameIn: char*, terminalIn: bool, dataIn: char*): symbol {
|
||||
fun symbol(nameIn: *char, terminalIn: bool, dataIn: *char): symbol {
|
||||
var toRet.construct(string::string(nameIn), terminalIn, string::string(dataIn)): symbol
|
||||
return toRet
|
||||
}
|
||||
@@ -25,12 +25,12 @@ obj symbol (Object) {
|
||||
var name: string::string
|
||||
var terminal: bool
|
||||
|
||||
fun construct(): symbol* {
|
||||
fun construct(): *symbol {
|
||||
data.construct()
|
||||
name.construct()
|
||||
return this
|
||||
}
|
||||
fun construct(nameIn: string::string, terminalIn: bool, dataIn: string::string): symbol* {
|
||||
fun construct(nameIn: string::string, terminalIn: bool, dataIn: string::string): *symbol {
|
||||
name.construct(nameIn)
|
||||
terminal = terminalIn
|
||||
data.construct(dataIn)
|
||||
@@ -40,7 +40,7 @@ obj symbol (Object) {
|
||||
data.destruct()
|
||||
name.destruct()
|
||||
}
|
||||
fun copy_construct(old: symbol*) {
|
||||
fun copy_construct(old: *symbol) {
|
||||
data.copy_construct(&old->data)
|
||||
name.copy_construct(&old->name)
|
||||
terminal = old->terminal
|
||||
@@ -53,7 +53,7 @@ obj symbol (Object) {
|
||||
return data == other.data && name == other.name && terminal == other.terminal;
|
||||
}
|
||||
fun to_string(): string::string {
|
||||
var terminalString: char*
|
||||
var terminalString: *char
|
||||
if (terminal)
|
||||
terminalString = "true"
|
||||
else
|
||||
|
||||
@@ -21,19 +21,19 @@ obj pair<T,U> (Object) {
|
||||
var first: T
|
||||
var second: U
|
||||
|
||||
fun construct(firstIn: T, secondIn: U): pair<T,U>* {
|
||||
fun construct(firstIn: T, secondIn: U): *pair<T,U> {
|
||||
mem::maybe_copy_construct(&first, &firstIn)
|
||||
mem::maybe_copy_construct(&second, &secondIn)
|
||||
return this
|
||||
}
|
||||
|
||||
fun construct(): pair<T,U>* {
|
||||
fun construct(): *pair<T,U> {
|
||||
mem::maybe_construct(&first)
|
||||
mem::maybe_construct(&second)
|
||||
return this
|
||||
}
|
||||
|
||||
fun copy_construct(old: pair<T,U>*):void {
|
||||
fun copy_construct(old: *pair<T,U>):void {
|
||||
mem::maybe_copy_construct(&first, &old->first)
|
||||
mem::maybe_copy_construct(&second, &old->second)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ obj range {
|
||||
var begin: int
|
||||
var end: int
|
||||
var step: int
|
||||
fun construct(beginIn: int, endIn: int, stepIn: int) : range* {
|
||||
fun construct(beginIn: int, endIn: int, stepIn: int) : *range {
|
||||
begin = beginIn
|
||||
end = endIn
|
||||
step = stepIn
|
||||
|
||||
@@ -14,18 +14,18 @@ fun vector<T>(in:T):vector<T> {
|
||||
}
|
||||
|
||||
obj vector<T> (Object) {
|
||||
var data: T*;
|
||||
var data: *T;
|
||||
var size: int;
|
||||
var available: int;
|
||||
|
||||
fun construct(): vector<T>* {
|
||||
fun construct(): *vector<T> {
|
||||
size = 0;
|
||||
available = 8;
|
||||
data = new<T>(8);
|
||||
return this;
|
||||
}
|
||||
|
||||
fun construct(newSize: int): vector<T>*{
|
||||
fun construct(newSize: int): *vector<T>{
|
||||
size = newSize;
|
||||
available = newSize;
|
||||
|
||||
@@ -33,7 +33,7 @@ obj vector<T> (Object) {
|
||||
return this;
|
||||
}
|
||||
|
||||
fun copy_construct(old: vector<T>*): void {
|
||||
fun copy_construct(old: *vector<T>): void {
|
||||
construct()
|
||||
for (var i = 0; i < old->size; i++;)
|
||||
addEnd(old->get(i))
|
||||
@@ -77,7 +77,7 @@ obj vector<T> (Object) {
|
||||
}
|
||||
|
||||
fun resize(newSize: int): bool {
|
||||
var newData: T* = new<T>(newSize);
|
||||
var newData: *T = new<T>(newSize);
|
||||
if (!newData)
|
||||
return false;
|
||||
for (var i: int = 0; i < lesser<int>(size, newSize); i++;)
|
||||
@@ -114,7 +114,7 @@ obj vector<T> (Object) {
|
||||
return data[index];
|
||||
}
|
||||
|
||||
fun getBackingMemory(): T* { return data; }
|
||||
fun getBackingMemory(): *T { return data; }
|
||||
|
||||
// This is a template for the interesting reason that structs
|
||||
// can not be compared for equality in C, and maybe we haven't defined equality
|
||||
|
||||
@@ -101,4 +101,3 @@ fun vector<T>(first:T, second:T, third:T, fourth:T, fifth:T, sixth:T, seventh:T,
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ fun qualified_func(): int { return 9; }
|
||||
|
||||
obj qualified_class {
|
||||
var number: int;
|
||||
fun construct(num: int): qualified_class* {
|
||||
fun construct(num: int): *qualified_class {
|
||||
number = num;
|
||||
return this;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ obj qualified_class {
|
||||
|
||||
obj qualified_container<T> {
|
||||
var data: T;
|
||||
fun construct(dataIn: T): qualified_container<T>* {
|
||||
fun construct(dataIn: T): *qualified_container<T> {
|
||||
data = dataIn;
|
||||
}
|
||||
fun get(): T {
|
||||
|
||||
@@ -3,7 +3,7 @@ fun unqualified_func(): int { return 10; }
|
||||
|
||||
obj unqualified_class {
|
||||
var number: int;
|
||||
fun construct(num: int): unqualified_class* {
|
||||
fun construct(num: int): *unqualified_class {
|
||||
number = num;
|
||||
return this;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ obj unqualified_class {
|
||||
|
||||
obj unqualified_container<T> {
|
||||
var data: T;
|
||||
fun construct(dataIn: T): unqualified_container<T>* {
|
||||
fun construct(dataIn: T): *unqualified_container<T> {
|
||||
data = dataIn;
|
||||
}
|
||||
fun get(): T {
|
||||
|
||||
@@ -4,7 +4,7 @@ fun retVoid() {
|
||||
println("Woooo")
|
||||
}
|
||||
|
||||
fun withParams(a:int, b:char*) {
|
||||
fun withParams(a:int, b:*char) {
|
||||
println(a)
|
||||
println(b)
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ obj ToClose {
|
||||
}
|
||||
|
||||
obj One (Object) {
|
||||
fun construct(): One* {
|
||||
fun construct(): *One {
|
||||
return this
|
||||
}
|
||||
fun destruct() {
|
||||
var a:One
|
||||
mem::safe_recursive_delete(&a, fun(it: One*): set::set<One*> { return set::set(it); } )
|
||||
mem::safe_recursive_delete(&a, fun(it: *One): set::set<*One> { return set::set(it); } )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ fun main():int {
|
||||
|
||||
var a = 1337
|
||||
var b = &a
|
||||
var c = cast_ptr<int*, char*>(b)
|
||||
var c = cast_ptr<*int, *char>(b)
|
||||
//var d = c + 1
|
||||
//var e = 1 + c
|
||||
println(to_int(*(c+0)))
|
||||
|
||||
@@ -3,7 +3,7 @@ import mem:*;
|
||||
|
||||
obj ClassWithConstructor {
|
||||
var data: int;
|
||||
fun construct(inData: int): ClassWithConstructor* {
|
||||
fun construct(inData: int): *ClassWithConstructor {
|
||||
data = inData;
|
||||
return this;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ fun main(): int {
|
||||
object.printData();
|
||||
var a: int = 8;
|
||||
println(a);
|
||||
var objPtr: ClassWithConstructor* = new<ClassWithConstructor>()->construct(11);
|
||||
var objPtr: *ClassWithConstructor = new<ClassWithConstructor>()->construct(11);
|
||||
objPtr->printData();
|
||||
delete<ClassWithConstructor>(objPtr);
|
||||
return 0;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import io:*
|
||||
|
||||
obj wDestructor {
|
||||
var data: char*
|
||||
var data: *char
|
||||
var count: int
|
||||
fun construct(dat:char*):wDestructor* {
|
||||
fun construct(dat:*char):*wDestructor {
|
||||
data = dat
|
||||
count = 0
|
||||
return this
|
||||
}
|
||||
fun copy_construct(other: wDestructor*):void {
|
||||
fun copy_construct(other: *wDestructor):void {
|
||||
data = other->data
|
||||
count = other->count + 1
|
||||
print("copy_construct ")
|
||||
@@ -17,7 +17,7 @@ obj wDestructor {
|
||||
print(count)
|
||||
println("!")
|
||||
}
|
||||
fun operator=(other: wDestructor*):void {
|
||||
fun operator=(other: *wDestructor):void {
|
||||
data = other->data
|
||||
count = other->count + 1
|
||||
print("copy assign ")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import io:*
|
||||
|
||||
obj FuncObj {
|
||||
fun operator()(a:int, b:char*): void {
|
||||
fun operator()(a:int, b:*char): void {
|
||||
println(a)
|
||||
println(b)
|
||||
}
|
||||
|
||||
@@ -18,15 +18,15 @@ fun printInt(it:int):void {
|
||||
}
|
||||
|
||||
|
||||
fun ptrFn<T>(ptr: T*):void {
|
||||
fun ptrFn<T>(ptr: *T):void {
|
||||
println(*ptr)
|
||||
}
|
||||
|
||||
fun traitAware<T>(it:T*):void {
|
||||
fun traitAware<T>(it:*T):void {
|
||||
println("Does not have Traits")
|
||||
}
|
||||
|
||||
fun traitAware<T(Traits)>(it:T*):void {
|
||||
fun traitAware<T(Traits)>(it:*T):void {
|
||||
println("Does have Traits")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import io:*
|
||||
|
||||
fun main():int {
|
||||
var wr: fun():int*
|
||||
var wa: fun():*int
|
||||
var wb: *fun():int
|
||||
var wc: *fun():*int
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -22,6 +22,6 @@ fun main():int {
|
||||
println(mapEx[7])
|
||||
println(mapEx[20])
|
||||
mapEx.remove(20)
|
||||
mapEx.for_each(fun(key:int, value:char*) { print("key: "); print(key); print(", value: "); println(value); })
|
||||
mapEx.for_each(fun(key:int, value:*char) { print("key: "); print(key); print(", value: "); println(value); })
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import io:*;
|
||||
obj AnObject {
|
||||
var a: int;
|
||||
var b: int;
|
||||
var c: char*;
|
||||
var c: *char;
|
||||
|
||||
fun print(): void {
|
||||
print(a+b);
|
||||
@@ -16,7 +16,7 @@ obj AnObject {
|
||||
|
||||
|
||||
fun main(): int {
|
||||
var ptr: AnObject* = new<AnObject>();
|
||||
var ptr: *AnObject = new<AnObject>();
|
||||
ptr->a = 4;
|
||||
ptr->b = 7;
|
||||
ptr->c = "Hello decent memory! Quite a nice feeling\n";
|
||||
|
||||
@@ -19,7 +19,7 @@ fun main(): int {
|
||||
var wooObject: firstObject;
|
||||
wooObject.objectNum = 7;
|
||||
print(wooObject.objectNum);
|
||||
var objPtr: firstObject* = &wooObject;
|
||||
var objPtr: *firstObject = &wooObject;
|
||||
objPtr->objectNum = 42;
|
||||
print(objPtr->objectNum);
|
||||
print("\n");
|
||||
|
||||
@@ -3,12 +3,12 @@ import trivial_container:*;
|
||||
|
||||
obj RegularObject {
|
||||
var num: int;
|
||||
var innerContainer: trivialContainer<char*>;
|
||||
fun set(message: char*, number: int): void {
|
||||
var innerContainer: trivialContainer<*char>;
|
||||
fun set(message: *char, number: int): void {
|
||||
innerContainer.data = message;
|
||||
num = number;
|
||||
}
|
||||
fun get(): char* {
|
||||
fun get(): *char {
|
||||
return innerContainer.data;
|
||||
}
|
||||
fun print(): void {
|
||||
@@ -21,7 +21,7 @@ def MyIntContainer trivialContainer<int>;
|
||||
var roundabout: MyIntContainer;
|
||||
var outsideDec: RegularObject;
|
||||
|
||||
fun print(toPrint: trivialContainer<char*>): void {
|
||||
fun print(toPrint: trivialContainer<*char>): void {
|
||||
print(toPrint.data);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ fun main(): int {
|
||||
var qClass.construct(11): scopeQualified::qualified_class;
|
||||
io::println(qClass.get());
|
||||
|
||||
var sayQualified.construct("Qualified Container!"): scopeQualified::qualified_container<char*>;
|
||||
var sayQualified.construct("Qualified Container!"): scopeQualified::qualified_container<*char>;
|
||||
io::println(sayQualified.get());
|
||||
io::println(scopeQualified::qualified_id<char*>("Even template functions qualified!"));
|
||||
io::println(scopeQualified::qualified_id<*char>("Even template functions qualified!"));
|
||||
|
||||
io::println();
|
||||
|
||||
@@ -24,9 +24,9 @@ fun main(): int {
|
||||
var uqClass.construct(12): unqualified_class;
|
||||
io::println(uqClass.get());
|
||||
|
||||
var sayUnqualified.construct("Unqualified Container!"): unqualified_container<char*>;
|
||||
var sayUnqualified.construct("Unqualified Container!"): unqualified_container<*char>;
|
||||
io::println(sayUnqualified.get());
|
||||
io::println(unqualified_id<char*>("Even template functions unqualified!"));
|
||||
io::println(unqualified_id<*char>("Even template functions unqualified!"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
obj Swapper<T> {
|
||||
fun doit(a: T*, b: T*) : void {
|
||||
fun doit(a: *T, b: *T) : void {
|
||||
var temp: T = *a;
|
||||
*a = *b;
|
||||
*b = temp;
|
||||
@@ -9,7 +9,7 @@ obj Swapper<T> {
|
||||
}
|
||||
|
||||
|
||||
fun swap<T>(a: T*, b: T*) : void {
|
||||
fun swap<T>(a: *T, b: *T) : void {
|
||||
var temp: T = *a
|
||||
*a = *b
|
||||
*b = temp;
|
||||
|
||||
@@ -16,8 +16,8 @@ obj TemplateTest<T,J> {
|
||||
|
||||
fun main(): int {
|
||||
|
||||
var test: TemplateTest<int, char*>;
|
||||
var test2: TemplateTest<char*, char*>;
|
||||
var test: TemplateTest<int, *char>;
|
||||
var test2: TemplateTest<*char, *char>;
|
||||
test.a = 24;
|
||||
test.b = "Hello World";
|
||||
test2.a = "Pi incoming";
|
||||
|
||||
@@ -17,7 +17,7 @@ obj TemplateTest<T> {
|
||||
fun main(): int {
|
||||
|
||||
var test: TemplateTest<int>;
|
||||
var test2: TemplateTest<char*>;
|
||||
var test2: TemplateTest<*char>;
|
||||
test.a = 5;
|
||||
test.b = 7;
|
||||
test2.a = 9;
|
||||
|
||||
@@ -23,7 +23,7 @@ fun main():int {
|
||||
aVec.addEnd(12)
|
||||
println(fromTemplateFun)
|
||||
println(idVec(aVec))
|
||||
var testPair: pair2<char*, int>
|
||||
var testPair: pair2<*char, int>
|
||||
testPair.first = "test string"
|
||||
testPair.second = 9
|
||||
var someFloat = 13.88
|
||||
|
||||
@@ -29,7 +29,7 @@ fun addAndPrint<T>(a: T, b: T): T {
|
||||
|
||||
fun main(): int {
|
||||
var test: TemplateTest<int>;
|
||||
var test2: TemplateTest<char*>;
|
||||
var test2: TemplateTest<*char>;
|
||||
test.a = 5;
|
||||
test.b = 7;
|
||||
test.c.data = 1337;
|
||||
@@ -40,7 +40,7 @@ fun main(): int {
|
||||
test.print();
|
||||
test2.print();
|
||||
|
||||
var testImport: trivialContainer<char*>;
|
||||
var testImport: trivialContainer<*char>;
|
||||
testImport.data = "From another file! Whoh!";
|
||||
testImport.print();
|
||||
print("\n");
|
||||
|
||||
@@ -3,7 +3,7 @@ import mem:*;
|
||||
|
||||
fun main(): int {
|
||||
var b: int;
|
||||
var a: int* = &b;
|
||||
var a: *int = &b;
|
||||
a [ 0 ] = 7;
|
||||
print(a [ 0 ] );
|
||||
print(*a);
|
||||
|
||||
@@ -48,14 +48,14 @@ fun main(): int {
|
||||
var c: Trait2;
|
||||
var d: TwoTrait;
|
||||
var e: AlreadySpecilized;
|
||||
var f: TwoTrait*;
|
||||
var f: *TwoTrait;
|
||||
|
||||
OneTwoFunc<NoTraits>(a);
|
||||
OneTwoFunc<Trait1>(b);
|
||||
OneTwoFunc<Trait2>(c);
|
||||
OneTwoFunc<TwoTrait>(d);
|
||||
// OneTwoFunc<AlreadySpecilized>(e);
|
||||
OneTwoFunc<TwoTrait*>(f);
|
||||
OneTwoFunc<*TwoTrait>(f);
|
||||
println();
|
||||
|
||||
OneTwoFunc(a);
|
||||
@@ -71,13 +71,13 @@ fun main(): int {
|
||||
var gamma: OneTwoObj<Trait2>;
|
||||
var delta: OneTwoObj<TwoTrait>;
|
||||
// |OneTwoObj<AlreadySpecilized>| epsilon;
|
||||
var zeta: OneTwoObj<TwoTrait*>;
|
||||
var zeta: OneTwoObj<*TwoTrait>;
|
||||
|
||||
OneTwoFunc<OneTwoObj<NoTraits>>(alpha);
|
||||
OneTwoFunc<OneTwoObj<Trait1>>(beta);
|
||||
OneTwoFunc<OneTwoObj<Trait2>>(gamma);
|
||||
OneTwoFunc<OneTwoObj<TwoTrait>>(delta);
|
||||
OneTwoFunc<OneTwoObj<TwoTrait*>>(zeta);
|
||||
OneTwoFunc<OneTwoObj<*TwoTrait>>(zeta);
|
||||
println()
|
||||
|
||||
OneTwoFunc(alpha);
|
||||
|
||||
@@ -2,7 +2,7 @@ import io;
|
||||
|
||||
obj ClassWithConstructor {
|
||||
var data: int;
|
||||
fun construct(inData: int): ClassWithConstructor* {
|
||||
fun construct(inData: int): *ClassWithConstructor {
|
||||
data = inData;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import io:*
|
||||
import mem:*
|
||||
import vector:*
|
||||
|
||||
fun retMessage(): char* {
|
||||
fun retMessage(): *char {
|
||||
return "I do like type inference"
|
||||
}
|
||||
fun id<T>(in: T): T { return in; }
|
||||
|
||||
@@ -3,19 +3,19 @@ import io:*
|
||||
|
||||
obj test(Object) {
|
||||
var counter:int
|
||||
fun construct(): test* {
|
||||
fun construct(): *test {
|
||||
counter = 0
|
||||
println("construct with 0")
|
||||
return this
|
||||
}
|
||||
|
||||
fun construct(it:int): test* {
|
||||
fun construct(it:int): *test {
|
||||
counter = it
|
||||
print("construct with "); println(it)
|
||||
return this
|
||||
}
|
||||
|
||||
fun copy_construct(old: test*):void {
|
||||
fun copy_construct(old: *test):void {
|
||||
counter = old->counter+1
|
||||
print("copy construct from "); print(old->counter); print(" to "); println(counter)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ obj AbleToBeDestroyed (Object) {
|
||||
print("Constructed: ")
|
||||
println(data)
|
||||
}
|
||||
fun copy_construct(other:AbleToBeDestroyed*):void {
|
||||
fun copy_construct(other:*AbleToBeDestroyed):void {
|
||||
data = other->data+1
|
||||
print("Copied: ")
|
||||
print(other->data)
|
||||
@@ -69,7 +69,7 @@ fun main(): int {
|
||||
vector(1,2,3,4,5,6,7,8,9,10,11,12).for_each(fun(i:int) { print(i); })
|
||||
println()
|
||||
|
||||
var desVec: vector<AbleToBeDestroyed>* = new<vector<AbleToBeDestroyed>>()->construct();
|
||||
var desVec: *vector<AbleToBeDestroyed> = new<vector<AbleToBeDestroyed>>()->construct();
|
||||
var testDestruct.construct(0): AbleToBeDestroyed;
|
||||
desVec->addEnd(testDestruct);
|
||||
println("delete vector")
|
||||
|
||||
Reference in New Issue
Block a user