Some bugfixes, allow overloading of [] and add that to vector and string, work on regex. Need closures before that finishes....
This commit is contained in:
@@ -9,19 +9,15 @@
|
|||||||
|
|
||||||
class RegExState {
|
class RegExState {
|
||||||
public:
|
public:
|
||||||
RegExState(RegExState* inInnerState);
|
|
||||||
RegExState(char inCharacter);
|
RegExState(char inCharacter);
|
||||||
RegExState();
|
RegExState();
|
||||||
|
|
||||||
~RegExState();
|
~RegExState();
|
||||||
|
|
||||||
void addNext(RegExState* nextState);
|
void addNext(RegExState* nextState);
|
||||||
bool characterIs(char inCharacter);
|
bool characterIs(char inCharacter);
|
||||||
std::vector<RegExState*>* advance(char advanceCharacter);
|
std::vector<RegExState*>* advance(char advanceCharacter);
|
||||||
std::vector<RegExState*>* getNextStates();
|
std::vector<RegExState*> getNextStates();
|
||||||
|
|
||||||
RegExState* getInner();
|
|
||||||
|
|
||||||
bool isGoal();
|
bool isGoal();
|
||||||
std::string toString();
|
std::string toString();
|
||||||
std::string toString(RegExState* avoid);
|
std::string toString(RegExState* avoid);
|
||||||
@@ -31,7 +27,6 @@ class RegExState {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<RegExState*> nextStates;
|
std::vector<RegExState*> nextStates;
|
||||||
RegExState* inner;
|
|
||||||
char character;
|
char character;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ scoped_identifier = scoped_identifier WS scope_op WS identifier | identifier ;
|
|||||||
|
|
||||||
#Note that to prevent confilct with nested templates (T<A<B>>) it is a nonterminal contructed as follows
|
#Note that to prevent confilct with nested templates (T<A<B>>) it is a nonterminal contructed as follows
|
||||||
right_shift = ">" ">" ;
|
right_shift = ">" ">" ;
|
||||||
overloadable_operator = "\+" | "-" | "\*" | "/" | "%" | "^" | "&" | "\|" | "~" | "!" | "," | "=" | "\+\+" | "--" | "<<" | right_shift | "==" | "!=" | "&&" | "\|\|" | "\+=" | "-=" | "/=" | "%=" | "^=" | "&=" | "\|=" | "\*=" | "<<=" | ">>=" | "->" | "\(" "\)" ;
|
overloadable_operator = "\+" | "-" | "\*" | "/" | "%" | "^" | "&" | "\|" | "~" | "!" | "," | "=" | "\+\+" | "--" | "<<" | right_shift | "==" | "!=" | "&&" | "\|\|" | "\+=" | "-=" | "/=" | "%=" | "^=" | "&=" | "\|=" | "\*=" | "<<=" | ">>=" | "->" | "\(" "\)" | "[]" ;
|
||||||
func_identifier = identifier | identifier overloadable_operator ;
|
func_identifier = identifier | identifier overloadable_operator ;
|
||||||
function = "fun" WS func_identifier WS template_dec WS "\(" WS opt_typed_parameter_list WS "\)" WS dec_type WS statement | "fun" WS func_identifier WS "\(" WS opt_typed_parameter_list WS "\)" WS dec_type WS statement ;
|
function = "fun" WS func_identifier WS template_dec WS "\(" WS opt_typed_parameter_list WS "\)" WS dec_type WS statement | "fun" WS func_identifier WS "\(" WS opt_typed_parameter_list WS "\)" WS dec_type WS statement ;
|
||||||
lambda = "fun" WS "\(" WS opt_typed_parameter_list WS "\)" WS dec_type WS statement ;
|
lambda = "fun" WS "\(" WS opt_typed_parameter_list WS "\)" WS dec_type WS statement ;
|
||||||
|
|||||||
@@ -972,7 +972,8 @@ NodeTree<ASTData>* ASTTransformation::templateClassLookup(NodeTree<ASTData>* sco
|
|||||||
int typeIndex = 0;
|
int typeIndex = 0;
|
||||||
int currentTraitsSatisfied = 0;
|
int currentTraitsSatisfied = 0;
|
||||||
for (auto j : nameTraitsPairs) {
|
for (auto j : nameTraitsPairs) {
|
||||||
if (!subset(j.second, templateInstantiationTypes[typeIndex]->traits)) {
|
// error out if not subset, or if we're a pointer but should have traits
|
||||||
|
if (!subset(j.second, templateInstantiationTypes[typeIndex]->traits) || (templateInstantiationTypes[typeIndex]->getIndirection() && j.second.size())) {
|
||||||
traitsEqual = false;
|
traitsEqual = false;
|
||||||
std::cout << "Traits not subset for " << j.first << " and " << templateInstantiationTypes[typeIndex]->toString() << ": ";
|
std::cout << "Traits not subset for " << j.first << " and " << templateInstantiationTypes[typeIndex]->toString() << ": ";
|
||||||
//std::cout << baseType << " " << indirection << " " << typeDefinition << " " << templateDefinition << " " << traits << ;
|
//std::cout << baseType << " " << indirection << " " << typeDefinition << " " << templateDefinition << " " << traits << ;
|
||||||
@@ -1137,7 +1138,8 @@ NodeTree<ASTData>* ASTTransformation::templateFunctionLookup(NodeTree<ASTData>*
|
|||||||
int typeIndex = 0;
|
int typeIndex = 0;
|
||||||
int currentTraitsSatisfied = 0;
|
int currentTraitsSatisfied = 0;
|
||||||
for (auto j : nameTraitsPairs) {
|
for (auto j : nameTraitsPairs) {
|
||||||
if (!subset(j.second, templateInstantiationTypesPerFunction[i][typeIndex]->traits)) {
|
// error out if not subset, or if we're a pointer but should have traits
|
||||||
|
if (!subset(j.second, templateInstantiationTypesPerFunction[i][typeIndex]->traits) || (templateInstantiationTypesPerFunction[i][typeIndex]->getIndirection() && j.second.size())) {
|
||||||
traitsEqual = false;
|
traitsEqual = false;
|
||||||
std::cout << "Traits not a subset for " << j.first << " and " << templateInstantiationTypesPerFunction[i][typeIndex]->toString() << ": |";
|
std::cout << "Traits not a subset for " << j.first << " and " << templateInstantiationTypesPerFunction[i][typeIndex]->toString() << ": |";
|
||||||
std::copy(j.second.begin(), j.second.end(), std::ostream_iterator<std::string>(std::cout, " "));
|
std::copy(j.second.begin(), j.second.end(), std::ostream_iterator<std::string>(std::cout, " "));
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
|
|||||||
return tabs() + stat.preValue + stat.value + ";\n" + stat.postValue ;
|
return tabs() + stat.preValue + stat.value + ";\n" + stat.postValue ;
|
||||||
}
|
}
|
||||||
case if_statement:
|
case if_statement:
|
||||||
output += "if (" + generate(children[0], enclosingObject, true).oneString() + ")\n\t";
|
output += "if (" + generate(children[0], enclosingObject, true) + ")\n\t";
|
||||||
// We have to see if the then statement is a regular single statement or a block.
|
// We have to see if the then statement is a regular single statement or a block.
|
||||||
// If it's a block, because it's also a statement a semicolon will be emitted even though
|
// If it's a block, because it's also a statement a semicolon will be emitted even though
|
||||||
// we don't want it to be, as if (a) {b}; else {c}; is not legal C, but if (a) {b} else {c}; is.
|
// we don't want it to be, as if (a) {b}; else {c}; is not legal C, but if (a) {b} else {c}; is.
|
||||||
@@ -798,16 +798,16 @@ std::string CGenerator::CifyName(std::string name) {
|
|||||||
"&", "amprsd",
|
"&", "amprsd",
|
||||||
"|", "pipe",
|
"|", "pipe",
|
||||||
"~", "tilde",
|
"~", "tilde",
|
||||||
"!", "exclamationpt",
|
"!", "exlmtnpt",
|
||||||
",", "comma",
|
",", "comma",
|
||||||
"=", "equals",
|
"=", "eq",
|
||||||
"++", "doubleplus",
|
"++", "dbplus",
|
||||||
"--", "doubleminus",
|
"--", "dbminus",
|
||||||
"<<", "doubleleft",
|
"<<", "dbleft",
|
||||||
">>", "doubleright",
|
">>", "dbright",
|
||||||
"::", "scopeop",
|
"::", "scopeop",
|
||||||
":", "colon",
|
":", "colon",
|
||||||
"==", "doubleequals",
|
"==", "dbq",
|
||||||
"!=", "notequals",
|
"!=", "notequals",
|
||||||
"&&", "doubleamprsnd",
|
"&&", "doubleamprsnd",
|
||||||
"||", "doublepipe",
|
"||", "doublepipe",
|
||||||
@@ -820,13 +820,13 @@ std::string CGenerator::CifyName(std::string name) {
|
|||||||
"|=", "pipeequals",
|
"|=", "pipeequals",
|
||||||
"*=", "starequals",
|
"*=", "starequals",
|
||||||
"<<=", "doublerightequals",
|
"<<=", "doublerightequals",
|
||||||
"<", "lessthan",
|
"<", "lt",
|
||||||
">", "greaterthan",
|
">", "gt",
|
||||||
">>=", "doubleleftequals",
|
">>=", "doubleleftequals",
|
||||||
"(", "openparen",
|
"(", "openparen",
|
||||||
")", "closeparen",
|
")", "closeparen",
|
||||||
"[", "openbracket",
|
"[", "obk",
|
||||||
"]", "closebracket",
|
"]", "cbk",
|
||||||
" ", "space",
|
" ", "space",
|
||||||
".", "dot",
|
".", "dot",
|
||||||
"->", "arrow" };
|
"->", "arrow" };
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ RegExState* RegEx::construct(std::vector<RegExState*>* ending, std::string patte
|
|||||||
int perenEnd = findPerenEnd(pattern, i);
|
int perenEnd = findPerenEnd(pattern, i);
|
||||||
RegExState* innerBegin = construct(&innerEnds, strSlice(pattern, i+1, perenEnd));
|
RegExState* innerBegin = construct(&innerEnds, strSlice(pattern, i+1, perenEnd));
|
||||||
i = perenEnd;
|
i = perenEnd;
|
||||||
std::vector<RegExState*> innerBegins = *(innerBegin->getNextStates());
|
std::vector<RegExState*> innerBegins = innerBegin->getNextStates();
|
||||||
if (alternating) {
|
if (alternating) {
|
||||||
for (std::vector<RegExState*>::size_type j = 0; j < previousStatesEnd.size(); j++)
|
for (std::vector<RegExState*>::size_type j = 0; j < previousStatesEnd.size(); j++)
|
||||||
for (std::vector<RegExState*>::size_type k = 0; k < innerBegins.size(); k++)
|
for (std::vector<RegExState*>::size_type k = 0; k < innerBegins.size(); k++)
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
#include "RegExState.h"
|
#include "RegExState.h"
|
||||||
|
|
||||||
RegExState::RegExState(RegExState* inInnerState) {
|
|
||||||
inner = inInnerState;
|
|
||||||
}
|
|
||||||
|
|
||||||
RegExState::RegExState(char inCharacter) {
|
RegExState::RegExState(char inCharacter) {
|
||||||
character = inCharacter;
|
character = inCharacter;
|
||||||
inner = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RegExState::RegExState() {
|
RegExState::RegExState() {
|
||||||
character = 0;
|
character = 0;
|
||||||
inner = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RegExState::~RegExState() {
|
RegExState::~RegExState() {
|
||||||
@@ -29,22 +23,17 @@ bool RegExState::characterIs(char inCharacter) {
|
|||||||
std::vector<RegExState*>* RegExState::advance(char advanceCharacter) {
|
std::vector<RegExState*>* RegExState::advance(char advanceCharacter) {
|
||||||
std::vector<RegExState*>* advanceStates = new std::vector<RegExState*>();
|
std::vector<RegExState*>* advanceStates = new std::vector<RegExState*>();
|
||||||
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
|
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
|
||||||
if (nextStates[i] != NULL && nextStates[i]->characterIs(advanceCharacter))
|
if (nextStates[i] != NULL && nextStates[i]->characterIs(advanceCharacter))
|
||||||
advanceStates->push_back(nextStates[i]);
|
advanceStates->push_back(nextStates[i]);
|
||||||
}
|
}
|
||||||
return advanceStates;
|
return advanceStates;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegExState* RegExState::getInner() {
|
std::vector<RegExState*> RegExState::getNextStates() {
|
||||||
return inner;
|
return nextStates;
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<RegExState*>* RegExState::getNextStates() {
|
|
||||||
return &nextStates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegExState::isGoal() {
|
bool RegExState::isGoal() {
|
||||||
//return inner == NULL && nextStates.size() == 0;
|
|
||||||
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++)
|
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++)
|
||||||
if (nextStates[i] == NULL)
|
if (nextStates[i] == NULL)
|
||||||
return true;
|
return true;
|
||||||
@@ -66,11 +55,6 @@ std::string RegExState::toString(std::vector<RegExState*>* avoid) {
|
|||||||
avoid->push_back(this);
|
avoid->push_back(this);
|
||||||
std::string string = "";
|
std::string string = "";
|
||||||
string += std::string("\"") + character + "\"";
|
string += std::string("\"") + character + "\"";
|
||||||
if (inner != NULL) {
|
|
||||||
string += "inner: ";
|
|
||||||
string += inner->toString(avoid);
|
|
||||||
string += " end inner ";
|
|
||||||
}
|
|
||||||
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
|
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
|
||||||
bool inAvoid = false;
|
bool inAvoid = false;
|
||||||
for (std::vector<RegExState*>::size_type j = 0; j < avoid->size(); j++) {
|
for (std::vector<RegExState*>::size_type j = 0; j < avoid->size(); j++) {
|
||||||
@@ -90,7 +74,6 @@ std::string RegExState::toString(std::vector<RegExState*>* avoid) {
|
|||||||
else
|
else
|
||||||
string += "->this";
|
string += "->this";
|
||||||
}
|
}
|
||||||
//std::cout << "inner = " << inner << " nextStates size = " << nextStates.size() <<std::endl;
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,16 @@ fun println<T>(toPrint: T) : void {
|
|||||||
fun print(toPrint: char*) : void {
|
fun print(toPrint: char*) : void {
|
||||||
__if_comp__ __C__ {
|
__if_comp__ __C__ {
|
||||||
simple_passthrough(toPrint = toPrint::) """
|
simple_passthrough(toPrint = toPrint::) """
|
||||||
printf(toPrint);
|
printf("%s", toPrint);
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fun print(toPrint: char) : void {
|
||||||
|
__if_comp__ __C__ {
|
||||||
|
simple_passthrough(toPrint = toPrint::) """
|
||||||
|
printf("%c", toPrint);
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|||||||
78
stdlib/regex.krak
Normal file
78
stdlib/regex.krak
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import io
|
||||||
|
import vector
|
||||||
|
import string
|
||||||
|
|
||||||
|
fun regex(in: char*):regex {
|
||||||
|
return regex(string::string(in))
|
||||||
|
}
|
||||||
|
fun regex(in: string::string):regex {
|
||||||
|
var out.construct(in):regex
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
obj regexState(Object) {
|
||||||
|
var character: char
|
||||||
|
var next_states: vector::vector<regexState*>
|
||||||
|
fun construct(charIn:char): regexState* {
|
||||||
|
character = charIn
|
||||||
|
next_states.construct()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
fun construct(): regexState* {
|
||||||
|
return construct(0)
|
||||||
|
}
|
||||||
|
fun copy_construct(old:regexState*): void {
|
||||||
|
character = regexState->character
|
||||||
|
next_states.copy_construct(®exState->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; } )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obj regex(Object) {
|
||||||
|
var regexString: string::string
|
||||||
|
var begin: regexState
|
||||||
|
fun construct(regexStringIn: string::string): regex* {
|
||||||
|
regexState.construct()
|
||||||
|
regexString.copy_construct(®exStringIn)
|
||||||
|
|
||||||
|
var traverse = &begin
|
||||||
|
for (var i = 0; i < regexString.length(); i++;) {
|
||||||
|
var next = new<regexState>()->construct(regexString[i])
|
||||||
|
traverse->next_states->add(next)
|
||||||
|
traverse = next
|
||||||
|
}
|
||||||
|
traverse->next_states->add(new<regexState>()->construct(1))
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
fun copy_construct(old:regex*):void {
|
||||||
|
begin.copy_construct(&old->begin)
|
||||||
|
regexString.copy_construct(&old->regexString)
|
||||||
|
}
|
||||||
|
fun destruct():void {
|
||||||
|
begin.destruct()
|
||||||
|
regexString.destruct()
|
||||||
|
}
|
||||||
|
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 = 0
|
||||||
|
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->character == 1; }))
|
||||||
|
longest = 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->character == 1; }))
|
||||||
|
return to_match.length()
|
||||||
|
return longest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
import vector;
|
import vector;
|
||||||
import mem;
|
import mem;
|
||||||
|
|
||||||
|
fun string(in:char*):string {
|
||||||
|
var out:string = in
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
obj string (Object) {
|
obj string (Object) {
|
||||||
var data: vector::vector<char>;
|
var data: vector::vector<char>;
|
||||||
fun construct(): string* {
|
fun construct(): string* {
|
||||||
@@ -33,6 +38,9 @@ obj string (Object) {
|
|||||||
data.destruct()
|
data.destruct()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun operator[](index: int): char { return data[index]; }
|
||||||
|
fun length():int { return data.size; }
|
||||||
|
|
||||||
fun operator=(str: char*): void {
|
fun operator=(str: char*): void {
|
||||||
destruct();
|
destruct();
|
||||||
construct(str)
|
construct(str)
|
||||||
|
|||||||
@@ -74,10 +74,8 @@ obj vector<T> (Object) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun at(index: int): T {
|
fun at(index: int): T { return get(index); }
|
||||||
return get(index);
|
fun operator[](index: int): T { return get(index); }
|
||||||
}
|
|
||||||
|
|
||||||
fun get(index: int): T {
|
fun get(index: int): T {
|
||||||
if (index < 0 || index >= size) {
|
if (index < 0 || index >= size) {
|
||||||
println("Vector access out of bounds! Retuning 0th element as sanest option");
|
println("Vector access out of bounds! Retuning 0th element as sanest option");
|
||||||
@@ -97,6 +95,7 @@ obj vector<T> (Object) {
|
|||||||
return;
|
return;
|
||||||
data[index] = dataIn;
|
data[index] = dataIn;
|
||||||
}
|
}
|
||||||
|
fun add(dataIn: T): void { addEnd(dataIn); }
|
||||||
fun addEnd(dataIn: T): void {
|
fun addEnd(dataIn: T): void {
|
||||||
size++;
|
size++;
|
||||||
if (size >= available)
|
if (size >= available)
|
||||||
@@ -117,5 +116,20 @@ obj vector<T> (Object) {
|
|||||||
newVec.addEnd(func(data[i]))
|
newVec.addEnd(func(data[i]))
|
||||||
return newVec
|
return newVec
|
||||||
}
|
}
|
||||||
|
fun flatten_map<U>(func: fun(T):vector<U>):vector<U> {
|
||||||
|
var newVec.construct(): vector<U>
|
||||||
|
for (var i = 0; i < size; i++;) {
|
||||||
|
var to_add = func(data[i])
|
||||||
|
for (var j = 0; j < to_add.size; j++;)
|
||||||
|
newVec.addEnd(to_add.get(j))
|
||||||
|
}
|
||||||
|
return newVec
|
||||||
|
}
|
||||||
|
fun any_true(func: fun(T):bool):bool {
|
||||||
|
for (var i = 0; i < size; i++;)
|
||||||
|
if (func(data[i]))
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
1
tests/test_regex.expected_results
Normal file
1
tests/test_regex.expected_results
Normal file
@@ -0,0 +1 @@
|
|||||||
|
a
|
||||||
9
tests/test_regex.krak
Normal file
9
tests/test_regex.krak
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import io:*
|
||||||
|
import regex:*
|
||||||
|
|
||||||
|
fun main():int {
|
||||||
|
var reg = regex("a")
|
||||||
|
println(reg.regexString)
|
||||||
|
println(reg.long_match("a"))
|
||||||
|
return 0
|
||||||
|
}
|
||||||
0
tests/test_regex/test_regex.results
Normal file
0
tests/test_regex/test_regex.results
Normal file
@@ -4,3 +4,5 @@ assignment overload2
|
|||||||
assignment overload with additional
|
assignment overload with additional
|
||||||
hope
|
hope
|
||||||
hope3
|
hope3
|
||||||
|
new way!
|
||||||
|
a
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ fun main(): int {
|
|||||||
var initilized:string::string = "hope"
|
var initilized:string::string = "hope"
|
||||||
io::println(initilized)
|
io::println(initilized)
|
||||||
io::println(initilized+ "3")
|
io::println(initilized+ "3")
|
||||||
|
var newWay = string::string("new way!")
|
||||||
|
io::println(newWay)
|
||||||
|
io::println(newWay[5])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,22 @@ No Traits
|
|||||||
First Trait
|
First Trait
|
||||||
Second Trait
|
Second Trait
|
||||||
Both Traits
|
Both Traits
|
||||||
|
No Traits
|
||||||
|
|
||||||
|
No Traits
|
||||||
|
First Trait
|
||||||
|
Second Trait
|
||||||
|
Both Traits
|
||||||
|
No Traits
|
||||||
|
|
||||||
First Trait
|
First Trait
|
||||||
Second Trait
|
Second Trait
|
||||||
Both Traits
|
Both Traits
|
||||||
No Traits
|
No Traits
|
||||||
|
First Trait
|
||||||
|
|
||||||
|
First Trait
|
||||||
|
Second Trait
|
||||||
|
Both Traits
|
||||||
|
No Traits
|
||||||
|
First Trait
|
||||||
|
|||||||
@@ -48,13 +48,22 @@ fun main(): int {
|
|||||||
var c: Trait2;
|
var c: Trait2;
|
||||||
var d: TwoTrait;
|
var d: TwoTrait;
|
||||||
var e: AlreadySpecilized;
|
var e: AlreadySpecilized;
|
||||||
|
var f: TwoTrait*;
|
||||||
|
|
||||||
OneTwoFunc<NoTraits>(a);
|
OneTwoFunc<NoTraits>(a);
|
||||||
OneTwoFunc<Trait1>(b);
|
OneTwoFunc<Trait1>(b);
|
||||||
OneTwoFunc<Trait2>(c);
|
OneTwoFunc<Trait2>(c);
|
||||||
OneTwoFunc<TwoTrait>(d);
|
OneTwoFunc<TwoTrait>(d);
|
||||||
// OneTwoFunc<AlreadySpecilized>(e);
|
// OneTwoFunc<AlreadySpecilized>(e);
|
||||||
|
OneTwoFunc<TwoTrait*>(f);
|
||||||
|
println();
|
||||||
|
|
||||||
|
OneTwoFunc(a);
|
||||||
|
OneTwoFunc(b);
|
||||||
|
OneTwoFunc(c);
|
||||||
|
OneTwoFunc(d);
|
||||||
|
// OneTwoFunc(e);
|
||||||
|
OneTwoFunc(f);
|
||||||
println();
|
println();
|
||||||
|
|
||||||
var alpha: OneTwoObj<NoTraits>;
|
var alpha: OneTwoObj<NoTraits>;
|
||||||
@@ -62,11 +71,20 @@ fun main(): int {
|
|||||||
var gamma: OneTwoObj<Trait2>;
|
var gamma: OneTwoObj<Trait2>;
|
||||||
var delta: OneTwoObj<TwoTrait>;
|
var delta: OneTwoObj<TwoTrait>;
|
||||||
// |OneTwoObj<AlreadySpecilized>| epsilon;
|
// |OneTwoObj<AlreadySpecilized>| epsilon;
|
||||||
|
var zeta: OneTwoObj<TwoTrait*>;
|
||||||
|
|
||||||
OneTwoFunc<OneTwoObj<NoTraits>>(alpha);
|
OneTwoFunc<OneTwoObj<NoTraits>>(alpha);
|
||||||
OneTwoFunc<OneTwoObj<Trait1>>(beta);
|
OneTwoFunc<OneTwoObj<Trait1>>(beta);
|
||||||
OneTwoFunc<OneTwoObj<Trait2>>(gamma);
|
OneTwoFunc<OneTwoObj<Trait2>>(gamma);
|
||||||
OneTwoFunc<OneTwoObj<TwoTrait>>(delta);
|
OneTwoFunc<OneTwoObj<TwoTrait>>(delta);
|
||||||
|
OneTwoFunc<OneTwoObj<TwoTrait*>>(zeta);
|
||||||
|
println()
|
||||||
|
|
||||||
|
OneTwoFunc(alpha);
|
||||||
|
OneTwoFunc(beta);
|
||||||
|
OneTwoFunc(gamma);
|
||||||
|
OneTwoFunc(delta);
|
||||||
|
OneTwoFunc(zeta);
|
||||||
|
|
||||||
//We can't pass along our inner part, so let's just make sure that it is the right object.
|
//We can't pass along our inner part, so let's just make sure that it is the right object.
|
||||||
//epsilon.proveSpecilized();
|
//epsilon.proveSpecilized();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
4
|
4
|
||||||
1337
|
1337
|
||||||
|
1337
|
||||||
26614
|
26614
|
||||||
9131321
|
9131321
|
||||||
15513
|
15513
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ fun main(): int {
|
|||||||
for (var i: int = 0; i < intVec.size; i++;)
|
for (var i: int = 0; i < intVec.size; i++;)
|
||||||
print(intVec.at(i));
|
print(intVec.at(i));
|
||||||
println();
|
println();
|
||||||
|
for (var i: int = 0; i < intVec.size; i++;)
|
||||||
|
print(intVec[i]);
|
||||||
|
println();
|
||||||
|
|
||||||
// in place lambda map
|
// in place lambda map
|
||||||
intVec.in_place(fun(it:int):int { return it*2; })
|
intVec.in_place(fun(it:int):int { return it*2; })
|
||||||
|
|||||||
Reference in New Issue
Block a user