Some more bugfixes, got regex working as well as the cpp version. (leaks memory like craaazy)
This commit is contained in:
@@ -532,9 +532,9 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
//Test for special functions only if what we're testing is, indeed, the definition, not a function call that returns a callable function pointer
|
//Test for special functions only if what we're testing is, indeed, the definition, not a function call that returns a callable function pointer
|
||||||
if (funcType == function) {
|
if (funcType == function) {
|
||||||
if (name == "++" || name == "--")
|
if (name == "++" || name == "--")
|
||||||
return generate(children[1], enclosingObject, true).oneString() + name;
|
return generate(children[1], enclosingObject, true) + name;
|
||||||
if ( (name == "*" || name == "&" || name == "!" || name == "-" || name == "+" ) && children.size() == 2) //Is dereference, not multiplication, address-of, or other unary operator
|
if ( (name == "*" || name == "&" || name == "!" || name == "-" || name == "+" ) && children.size() == 2) //Is dereference, not multiplication, address-of, or other unary operator
|
||||||
return name + "(" + generate(children[1], enclosingObject, true).oneString() + ")";
|
return name + "(" + generate(children[1], enclosingObject, true) + ")";
|
||||||
if (name == "[]")
|
if (name == "[]")
|
||||||
return "(" + generate(children[1], enclosingObject, true) + ")[" + generate(children[2],enclosingObject, true) + "]";
|
return "(" + generate(children[1], enclosingObject, true) + ")[" + generate(children[2],enclosingObject, true) + "]";
|
||||||
if (name == "+" || name == "-" || name == "*" || name == "/" || name == "==" || name == ">=" || name == "<=" || name == "!="
|
if (name == "+" || name == "-" || name == "*" || name == "/" || name == "==" || name == ">=" || name == "<=" || name == "!="
|
||||||
@@ -559,16 +559,16 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType);
|
nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType);
|
||||||
// Note that we only add scoping to the object, as this specifies our member function too
|
// Note that we only add scoping to the object, as this specifies our member function too
|
||||||
/*HERE*/ return function_header + scopePrefix(unaliasedTypeDef) + CifyName(unaliasedTypeDef->getDataRef()->symbol.getName()) +"__" +
|
/*HERE*/ return function_header + scopePrefix(unaliasedTypeDef) + CifyName(unaliasedTypeDef->getDataRef()->symbol.getName()) +"__" +
|
||||||
CifyName(functionName + nameDecoration) + "(" + (name == "." ? "&" : "") + generate(children[1], enclosingObject, true).oneString() + ",";
|
CifyName(functionName + nameDecoration) + "(" + (name == "." ? "&" : "") + generate(children[1], enclosingObject, true) + ",";
|
||||||
//The comma lets the upper function call know we already started the param list
|
//The comma lets the upper function call know we already started the param list
|
||||||
//Note that we got here from a function call. We just pass up this special case and let them finish with the perentheses
|
//Note that we got here from a function call. We just pass up this special case and let them finish with the perentheses
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Is not in scope or not type" << std::endl;
|
std::cout << "Is not in scope or not type" << std::endl;
|
||||||
return "((" + generate(children[1], enclosingObject, true).oneString() + ")" + name + functionName + ")";
|
return "((" + generate(children[1], enclosingObject, true) + ")" + name + functionName + ")";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Is not in scope or not type" << std::endl;
|
std::cout << "Is not in scope or not type" << std::endl;
|
||||||
return "((" + generate(children[1], enclosingObject, true).oneString() + ")" + name + functionName + ")";
|
return "((" + generate(children[1], enclosingObject, true) + ")" + name + functionName + ")";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//return "((" + generate(children[1], enclosingObject) + ")" + name + generate(children[2], enclosingObject) + ")";
|
//return "((" + generate(children[1], enclosingObject) + ")" + name + generate(children[2], enclosingObject) + ")";
|
||||||
@@ -594,9 +594,9 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
} else {
|
} else {
|
||||||
//This part handles cases where our definition isn't the function definition (that is, it is probabally the return from another function)
|
//This part handles cases where our definition isn't the function definition (that is, it is probabally the return from another function)
|
||||||
//It's probabally the result of an access function call (. or ->) to access an object method.
|
//It's probabally the result of an access function call (. or ->) to access an object method.
|
||||||
std::string functionCallSource = generate(children[0], enclosingObject, true).oneString();
|
CCodeTriple functionCallSource = generate(children[0], enclosingObject, true);
|
||||||
if (functionCallSource[functionCallSource.size()-1] == ',') //If it's a member method, it's already started the parameter list.
|
if (functionCallSource.value[functionCallSource.value.size()-1] == ',') //If it's a member method, it's already started the parameter list.
|
||||||
output += children.size() > 1 ? functionCallSource : functionCallSource.substr(0, functionCallSource.size()-1);
|
output += children.size() > 1 ? functionCallSource : CCodeTriple(functionCallSource.preValue, functionCallSource.value.substr(0, functionCallSource.value.size()-1), functionCallSource.postValue);
|
||||||
else
|
else
|
||||||
output += functionCallSource + "(";
|
output += functionCallSource + "(";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,33 +52,25 @@ obj regexState(Object) {
|
|||||||
|
|
||||||
obj regex(Object) {
|
obj regex(Object) {
|
||||||
var regexString: string::string
|
var regexString: string::string
|
||||||
var begin: regexState
|
var begin: regexState*
|
||||||
|
|
||||||
fun construct(regexStringIn: string::string): regex* {
|
fun construct(regexStringIn: string::string): regex* {
|
||||||
begin.construct()
|
|
||||||
regexString.copy_construct(®exStringIn)
|
regexString.copy_construct(®exStringIn)
|
||||||
|
|
||||||
var beginningAndEnd = compile(regexStringIn)
|
var beginningAndEnd = compile(regexStringIn)
|
||||||
// add each beginning state as a next state of our begin, and the end state as the next state of each end
|
// init our begin, and the end state as the next state of each end
|
||||||
beginningAndEnd.first.do(fun(it: regexState*, begin: regexState*): void { begin->next_states.add(it); }, &begin)
|
begin = beginningAndEnd.first
|
||||||
beginningAndEnd.second.do(fun(it: regexState*, end: regexState*): void { it->next_states.add(end); }, mem::new<regexState>()->construct(conversions::to_char(1)))
|
beginningAndEnd.second.do(fun(it: regexState*, end: regexState*): void { it->next_states.add(end); }, mem::new<regexState>()->construct(conversions::to_char(1)))
|
||||||
|
|
||||||
io::print("begin: ")
|
|
||||||
beginningAndEnd.first.do(fun(it: regexState*): void { io::print(it->character); })
|
|
||||||
io::print("\nend: ")
|
|
||||||
beginningAndEnd.second.do(fun(it: regexState*): void { io::print(it->character); })
|
|
||||||
io::println()
|
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun copy_construct(old:regex*):void {
|
fun copy_construct(old:regex*):void {
|
||||||
begin.copy_construct(&old->begin)
|
begin = old->begin
|
||||||
regexString.copy_construct(&old->regexString)
|
regexString.copy_construct(&old->regexString)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destruct():void {
|
fun destruct():void {
|
||||||
begin.destruct()
|
//begin->destruct()
|
||||||
regexString.destruct()
|
regexString.destruct()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +79,7 @@ obj regex(Object) {
|
|||||||
construct(other.regexString)
|
construct(other.regexString)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun compile(regex_string: string::string): util::pair<vector::vector<regexState*>, vector::vector<regexState*>> {
|
fun compile(regex_string: string::string): util::pair<regexState*, vector::vector<regexState*>> {
|
||||||
var first = mem::new<regexState>()->construct()
|
var first = mem::new<regexState>()->construct()
|
||||||
var previous_begin = vector::vector<regexState*>()
|
var previous_begin = vector::vector<regexState*>()
|
||||||
var previous_end = vector::vector<regexState*>()
|
var previous_end = vector::vector<regexState*>()
|
||||||
@@ -97,7 +89,7 @@ obj regex(Object) {
|
|||||||
var escapeing = false
|
var escapeing = false
|
||||||
|
|
||||||
for (var i = 0; i < regex_string.length(); i++;) {
|
for (var i = 0; i < regex_string.length(); i++;) {
|
||||||
//io::print("i: "); io::println(i)
|
//io::print("i: "); io::print(i); io::print(" : "); io::println(regex_string[i])
|
||||||
if (regex_string[i] == '*' && !escapeing) {
|
if (regex_string[i] == '*' && !escapeing) {
|
||||||
for (var j = 0; j < current_end.size; j++;)
|
for (var j = 0; j < current_end.size; j++;)
|
||||||
current_end[j]->next_states.add_all(current_begin)
|
current_end[j]->next_states.add_all(current_begin)
|
||||||
@@ -114,6 +106,31 @@ obj regex(Object) {
|
|||||||
} else if (regex_string[i] == '|' && !escapeing) {
|
} else if (regex_string[i] == '|' && !escapeing) {
|
||||||
alternating = true
|
alternating = true
|
||||||
} else if (regex_string[i] == '(' && !escapeing) {
|
} else if (regex_string[i] == '(' && !escapeing) {
|
||||||
|
// note that we don't have a ')' case, as we skip past it with our indicies
|
||||||
|
var perenEnd = i + 1
|
||||||
|
for (var depth = 1; depth > 0; perenEnd++;)
|
||||||
|
if (regex_string[perenEnd] == '(')
|
||||||
|
depth++
|
||||||
|
else if (regex_string[perenEnd] == ')')
|
||||||
|
depth--
|
||||||
|
//io::print("unperened: ")
|
||||||
|
//io::println(regex_string.slice(i+1, perenEnd-1))
|
||||||
|
var innerBeginEnd = compile(regex_string.slice(i+1, perenEnd-1))
|
||||||
|
// NOTE: perenEnd is one past the close peren
|
||||||
|
i = perenEnd-1
|
||||||
|
|
||||||
|
if (alternating) {
|
||||||
|
previous_end.do(fun(it: regexState*, innerBegin: vector::vector<regexState*>):void { it->next_states.add_all(innerBegin); }, innerBeginEnd.first->next_states)
|
||||||
|
current_begin.add_all(innerBeginEnd.first->next_states)
|
||||||
|
current_end.add_all(innerBeginEnd.second)
|
||||||
|
} else {
|
||||||
|
current_end.do(fun(it: regexState*, innerBegin: vector::vector<regexState*>):void { it->next_states.add_all(innerBegin); }, innerBeginEnd.first->next_states)
|
||||||
|
previous_begin = current_begin
|
||||||
|
previous_end = current_end
|
||||||
|
current_begin = innerBeginEnd.first->next_states
|
||||||
|
current_end = innerBeginEnd.second
|
||||||
|
}
|
||||||
|
alternating = false
|
||||||
} else if (regex_string[i] == '\\' && !escapeing) {
|
} else if (regex_string[i] == '\\' && !escapeing) {
|
||||||
escapeing = true
|
escapeing = true
|
||||||
} else {
|
} else {
|
||||||
@@ -123,8 +140,8 @@ obj regex(Object) {
|
|||||||
current_begin.add(next)
|
current_begin.add(next)
|
||||||
current_end.add(next)
|
current_end.add(next)
|
||||||
} else {
|
} else {
|
||||||
current_end.do(fun(it: regexState*, next: regexState*):void { io::print("adding: "); io::print(next->character); io::print(" to "); io::println(it->character); it->next_states.add(next); }, next)
|
current_end.do(fun(it: regexState*, next: regexState*):void { it->next_states.add(next); }, next)
|
||||||
//current_end.do(fun(it: regexState*, next: regexState*):void { it->next_states.add(next); }, next)
|
//current_end.do(fun(it: regexState*, next: regexState*):void { io::print("adding: "); io::print(next->character); io::print(" to "); io::println(it->character); it->next_states.add(next); }, next)
|
||||||
//io::print("previous_begin size before current: "); io::println(previous_begin.size)
|
//io::print("previous_begin size before current: "); io::println(previous_begin.size)
|
||||||
//io::print("current_begin size before current: "); io::println(current_begin.size)
|
//io::print("current_begin size before current: "); io::println(current_begin.size)
|
||||||
previous_begin = current_begin
|
previous_begin = current_begin
|
||||||
@@ -134,33 +151,27 @@ obj regex(Object) {
|
|||||||
//io::print("current_begin size after current: "); io::println(current_begin.size)
|
//io::print("current_begin size after current: "); io::println(current_begin.size)
|
||||||
current_end = vector::vector(next)
|
current_end = vector::vector(next)
|
||||||
}
|
}
|
||||||
|
escapeing = false
|
||||||
|
alternating = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var beginAndEnd = util::make_pair(first->next_states, current_end)
|
var beginAndEnd = util::make_pair(first, current_end)
|
||||||
mem::delete(first)
|
|
||||||
return beginAndEnd
|
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 {
|
fun long_match(to_match: string::string): int {
|
||||||
var next = vector::vector(&begin)
|
var next = vector::vector(begin)
|
||||||
var longest = 0
|
var longest = -1
|
||||||
for (var i = 0; i < to_match.length(); i++;) {
|
for (var i = 0; i < to_match.length(); i++;) {
|
||||||
if (next.size == 0)
|
if (next.size == 0)
|
||||||
return longest
|
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
|
longest = i
|
||||||
//next = next.flatten_map<regexState*>(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<regexState*>(fun(state: regexState*): vector::vector<regexState*> { return state->match('a'); })
|
|
||||||
//next = next.flatten_map(fun(state: regexState*): vector::vector<regexState*> { return state->match('a'); })
|
|
||||||
next = next.flatten_map(fun(state: regexState*, c:char): vector::vector<regexState*> { return state->match(c); }, to_match[i])
|
next = next.flatten_map(fun(state: regexState*, c:char): vector::vector<regexState*> { return state->match(c); }, to_match[i])
|
||||||
}
|
}
|
||||||
/*io::println("ok, ending with")*/
|
|
||||||
/*for (var i = 0; i < next.size; i++;) {*/
|
|
||||||
/*io::println(next[i]->character)*/
|
|
||||||
/*io::println(conversions::to_int(next[i]->next_states[0]->character))*/
|
|
||||||
/*}*/
|
|
||||||
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 to_match.length()
|
||||||
return longest
|
return longest
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ obj string (Object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun operator[](index: int): char { return data[index]; }
|
fun operator[](index: int): char { return data[index]; }
|
||||||
|
fun slice(first: int, second: int): string {
|
||||||
|
var new.construct(data.slice(first,second)): string
|
||||||
|
return new
|
||||||
|
}
|
||||||
fun length():int { return data.size; }
|
fun length():int { return data.size; }
|
||||||
|
|
||||||
fun operator=(str: char*): void {
|
fun operator=(str: char*): void {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ obj vector<T> (Object) {
|
|||||||
fun destruct(): void {
|
fun destruct(): void {
|
||||||
if (data)
|
if (data)
|
||||||
delete(data, size);
|
delete(data, size);
|
||||||
|
//data = 1337
|
||||||
data = 0
|
data = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +85,17 @@ obj vector<T> (Object) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun slice(start: int, end: int): vector<T> {
|
||||||
|
var new.construct(): vector<T>
|
||||||
|
if (start < 0)
|
||||||
|
start += size + 1
|
||||||
|
if (end < 0)
|
||||||
|
end += size + 1
|
||||||
|
for (var i = start; i < end; i++;)
|
||||||
|
new.add(data[i])
|
||||||
|
return new
|
||||||
|
}
|
||||||
|
|
||||||
fun at(index: int): T { return get(index); }
|
fun at(index: int): T { return get(index); }
|
||||||
fun operator[](index: int): T { return get(index); }
|
fun operator[](index: int): T { return get(index); }
|
||||||
fun get(index: int): T {
|
fun get(index: int): T {
|
||||||
|
|||||||
@@ -1,2 +1,42 @@
|
|||||||
|
concat
|
||||||
2
|
2
|
||||||
|
-1
|
||||||
|
repitition
|
||||||
|
2
|
||||||
|
18
|
||||||
|
26
|
||||||
|
-1
|
||||||
|
-1
|
||||||
|
-1
|
||||||
|
alternation
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
-1
|
||||||
|
perens!
|
||||||
|
1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
2
|
||||||
|
2
|
||||||
|
12
|
||||||
0
|
0
|
||||||
|
optional!
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
Old Contributed
|
||||||
|
1
|
||||||
|
2
|
||||||
|
4
|
||||||
|
0
|
||||||
|
2
|
||||||
|
4
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
5
|
||||||
|
0
|
||||||
|
6
|
||||||
|
9
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ import io:*
|
|||||||
import regex:*
|
import regex:*
|
||||||
|
|
||||||
fun main():int {
|
fun main():int {
|
||||||
|
println("concat")
|
||||||
var reg = regex("ab")
|
var reg = regex("ab")
|
||||||
println(reg.long_match("abab"))
|
println(reg.long_match("abab"))
|
||||||
println(reg.long_match("aab"))
|
println(reg.long_match("aab"))
|
||||||
|
|
||||||
println("second")
|
println("repitition")
|
||||||
|
|
||||||
reg = regex("a*b+c")
|
reg = regex("a*b+c")
|
||||||
println(reg.long_match("bc"))
|
println(reg.long_match("bc"))
|
||||||
@@ -15,5 +16,54 @@ fun main():int {
|
|||||||
println(reg.long_match("aaaaaaaaaaaaaaaa"))
|
println(reg.long_match("aaaaaaaaaaaaaaaa"))
|
||||||
println(reg.long_match("aaaaaaaaaaaaaaaac"))
|
println(reg.long_match("aaaaaaaaaaaaaaaac"))
|
||||||
println(reg.long_match("aaaaaaaaaaaaaaaab"))
|
println(reg.long_match("aaaaaaaaaaaaaaaab"))
|
||||||
|
|
||||||
|
println("alternation")
|
||||||
|
|
||||||
|
reg = regex("a|b")
|
||||||
|
println(reg.long_match("a"))
|
||||||
|
println(reg.long_match("b"))
|
||||||
|
println(reg.long_match("aa"))
|
||||||
|
println(reg.long_match("bb"))
|
||||||
|
println(reg.long_match("ab"))
|
||||||
|
println(reg.long_match("c"))
|
||||||
|
|
||||||
|
println("perens!")
|
||||||
|
reg = regex("(a|b)*")
|
||||||
|
println(reg.long_match("a"))
|
||||||
|
println(reg.long_match("b"))
|
||||||
|
println(reg.long_match("aa"))
|
||||||
|
println(reg.long_match("bb"))
|
||||||
|
println(reg.long_match("ab"))
|
||||||
|
println(reg.long_match("abbbaaababab"))
|
||||||
|
println(reg.long_match("c"))
|
||||||
|
|
||||||
|
println("optional!")
|
||||||
|
reg = regex("a?b")
|
||||||
|
println(reg.long_match("a"))
|
||||||
|
println(reg.long_match("b"))
|
||||||
|
println(reg.long_match("ab"))
|
||||||
|
|
||||||
|
println("Old Contributed")
|
||||||
|
var re = regex("a*");
|
||||||
|
println(re.long_match("a"));
|
||||||
|
println(re.long_match("aa"));
|
||||||
|
println(re.long_match("aaaab"));
|
||||||
|
println(re.long_match("b"));
|
||||||
|
|
||||||
|
re = regex("a+");
|
||||||
|
println(re.long_match("aa"));
|
||||||
|
println(re.long_match("aaaab"));
|
||||||
|
println(re.long_match("b"));
|
||||||
|
|
||||||
|
re = regex("a(bc)?");
|
||||||
|
println(re.long_match("ab"));
|
||||||
|
|
||||||
|
re = regex("((ab)|c)*");
|
||||||
|
println(re.long_match("ababc"));
|
||||||
|
println(re.long_match("ad"));
|
||||||
|
println(re.long_match("ababccd"));
|
||||||
|
|
||||||
|
re = regex("bbb((bba+)|(ba+))*a*((a+b)|(a+bb)|(a+))*bbb") ;
|
||||||
|
println(re.long_match("bbbababbbaaaaaaaaaaaaaaaaaaabbb"));
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ import io:*
|
|||||||
import mem:*
|
import mem:*
|
||||||
import vector:*
|
import vector:*
|
||||||
|
|
||||||
obj pair<T, U> {
|
// pair2 because we actually have a pair now
|
||||||
|
|
||||||
|
obj pair2<T, U> {
|
||||||
var first: T
|
var first: T
|
||||||
var second: U
|
var second: U
|
||||||
}
|
}
|
||||||
|
|
||||||
fun id<T>(in: T): T { return in; }
|
fun id<T>(in: T): T { return in; }
|
||||||
fun idVec<T>(in: vector<T>): T { return in.get(0); }
|
fun idVec<T>(in: vector<T>): T { return in.get(0); }
|
||||||
fun pairFun<T>(in: pair<T, int>, another:double): T {
|
fun pairFun<T>(in: pair2<T, int>, another:double): T {
|
||||||
println(in.second)
|
println(in.second)
|
||||||
println(another)
|
println(another)
|
||||||
return in.first;
|
return in.first;
|
||||||
@@ -21,7 +23,7 @@ fun main():int {
|
|||||||
aVec.addEnd(12)
|
aVec.addEnd(12)
|
||||||
println(fromTemplateFun)
|
println(fromTemplateFun)
|
||||||
println(idVec(aVec))
|
println(idVec(aVec))
|
||||||
var testPair: pair<char*, int>
|
var testPair: pair2<char*, int>
|
||||||
testPair.first = "test string"
|
testPair.first = "test string"
|
||||||
testPair.second = 9
|
testPair.second = 9
|
||||||
var someFloat = 13.88
|
var someFloat = 13.88
|
||||||
|
|||||||
@@ -16,5 +16,10 @@ hayyy
|
|||||||
first
|
first
|
||||||
first
|
first
|
||||||
second
|
second
|
||||||
|
full: 1234
|
||||||
|
middle: 23
|
||||||
|
all but first: 234
|
||||||
|
all but last: 123
|
||||||
|
just some: 2
|
||||||
done
|
done
|
||||||
Destroyed: 0
|
Destroyed: 0
|
||||||
|
|||||||
@@ -85,6 +85,26 @@ fun main(): int {
|
|||||||
println(assignTest[0])
|
println(assignTest[0])
|
||||||
println(assignTest[1])
|
println(assignTest[1])
|
||||||
|
|
||||||
|
var sliceTest = vector(1)
|
||||||
|
sliceTest.add(2)
|
||||||
|
sliceTest.add(3)
|
||||||
|
sliceTest.add(4)
|
||||||
|
print("full: ")
|
||||||
|
sliceTest.do(fun(it:int):void print(it);)
|
||||||
|
println()
|
||||||
|
print("middle: ")
|
||||||
|
sliceTest.slice(1,-2).do(fun(it:int):void print(it);)
|
||||||
|
println()
|
||||||
|
print("all but first: ")
|
||||||
|
sliceTest.slice(1,-1).do(fun(it:int):void print(it);)
|
||||||
|
println()
|
||||||
|
print("all but last: ")
|
||||||
|
sliceTest.slice(0,-2).do(fun(it:int):void print(it);)
|
||||||
|
println()
|
||||||
|
print("just some: ")
|
||||||
|
sliceTest.slice(1,2).do(fun(it:int):void print(it);)
|
||||||
|
println()
|
||||||
|
|
||||||
println("done")
|
println("done")
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user