From e37836aea5051d5d71d57d1464009c1d2c354131 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sat, 4 Apr 2015 01:32:40 -0400 Subject: [PATCH] Working toward new C inline style --- include/ASTData.h | 4 +- include/ASTTransformation.h | 3 + include/CGenerator.h | 1 + krakenGrammer.kgm | 26 ++++---- src/ASTData.cpp | 2 + src/ASTTransformation.cpp | 129 +++++++++++++++++++++--------------- src/CGenerator.cpp | 72 +++++++++++++------- src/Importer.cpp | 6 +- stdlib/io.krak | 10 +-- stdlib/math.krak | 30 ++++----- stdlib/mem.krak | 12 ++-- 11 files changed, 172 insertions(+), 123 deletions(-) diff --git a/include/ASTData.h b/include/ASTData.h index 48bee63..5ff182b 100644 --- a/include/ASTData.h +++ b/include/ASTData.h @@ -16,7 +16,7 @@ class Type; enum ASTType {undef, translation_unit, interpreter_directive, import, identifier, type_def, function, code_block, typed_parameter, expression, boolean_expression, statement, if_statement, while_loop, for_loop, return_statement, assignment_statement, declaration_statement, - if_comp, simple_passthrough, function_call, value}; + if_comp, simple_passthrough, passthrough_params, function_call, value}; class ASTData { public: @@ -34,4 +34,4 @@ class ASTData { }; -#endif \ No newline at end of file +#endif diff --git a/include/ASTTransformation.h b/include/ASTTransformation.h index ec823ec..40bcd31 100644 --- a/include/ASTTransformation.h +++ b/include/ASTTransformation.h @@ -47,13 +47,16 @@ class ASTTransformation: public NodeTransformation { std::vector*> scopeLookup(NodeTree* scope, std::string lookup, bool includeModules, std::vector*> visited); NodeTree* getUpperTranslationUnit(NodeTree* node); + NodeTree* addToScope(std::string name, NodeTree* toAdd, NodeTree* addTo); Type* typeFromTypeNode(NodeTree* typeNode, NodeTree* scope, std::map templateTypeReplacements); NodeTree* templateClassLookup(NodeTree* scope, std::string name, std::vector templateInstantiationTypes); NodeTree* findOrInstantiateFunctionTemplate(std::vector*> children, NodeTree* scope, std::vector types, std::map templateTypeReplacements); std::map makeTemplateFunctionTypeMap(NodeTree* templateNode, std::vector types); std::vector>> makeTemplateNameTraitPairs(NodeTree* templateNode); + private: Importer * importer; + NodeTree* builtin_trans_unit; // the top scope for language level stuff std::map*>> languageLevelReservedWords; std::map*>> languageLevelOperators; NodeTree* topScope; //maintained for templates that need to add themselves to the top scope no matter where they are instantiated diff --git a/include/CGenerator.h b/include/CGenerator.h index 1dfb99f..d45d522 100644 --- a/include/CGenerator.h +++ b/include/CGenerator.h @@ -31,6 +31,7 @@ class CGenerator { static std::string ValueTypeToCTypeDecoration(Type *type); static std::string ValueTypeToCTypeThingHelper(Type *type, std::string ptrStr); static std::string CifyName(std::string name); + static std::string scopePrefix(NodeTree* from); std::string generateObjectMethod(NodeTree* enclosingObject, NodeTree* from, std::string *functionPrototype); NodeTree* getMethodsObjectType(NodeTree* scope, std::string functionName); std::string generatorString; diff --git a/krakenGrammer.kgm b/krakenGrammer.kgm index 45d8d6b..a5fe94d 100644 --- a/krakenGrammer.kgm +++ b/krakenGrammer.kgm @@ -1,5 +1,5 @@ Goal = translation_unit ; -translation_unit = interpreter_directive WS unorderd_list_part WS ; +translation_unit = WS unorderd_list_part WS ; unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def WS SEMI WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement WS SEMI WS unorderd_list_part | import | function | type_def WS SEMI | if_comp | simple_passthrough | declaration_statement WS SEMI ; type = type WS "\*" | "void" | "int" | "float" | "double" | "char" | scoped_identifier | scoped_identifier WS template_inst ; @@ -15,12 +15,6 @@ template_param = identifier WS traits | identifier ; import = "import" WS identifier WS SEMI | "import" WS identifier WS ":" WS "\*" WS SEMI | "import" WS identifier WS ":" WS import_list WS SEMI ; import_list = identifier | identifier WS "," WS import_list ; -interpreter_directive = "#!" WS path | ; -path = path path_part | path_part ; -path_part = forward_slash alphanumeric | back_slash alphanumeric ; -forward_slash = "/" ; -back_slash = "\\" ; - # all for optional semicolons k k line_break = " +" ; @@ -33,7 +27,11 @@ SEMI = ";" | line_break | cpp_comment ; if_comp = "__if_comp__" WS identifier WS if_comp_pred ; if_comp_pred = code_block | simple_passthrough ; -simple_passthrough = "__simple_passthrough__" WS triple_quoted_string ; +simple_passthrough = "simple_passthrough" WS passthrough_params WS triple_quoted_string ; +passthrough_params = "\(" WS opt_param_assign_list WS ":" WS opt_param_assign_list WS ":" WS opt_string WS "\)" | ; +opt_param_assign_list = param_assign_list | ; +param_assign_list = identifier WS "=" WS identifier | identifier WS "=" WS identifier WS "," WS param_assign_list ; +opt_string = string | ; triple_quoted_string = "\"\"\"((\"\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+)|(\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| @@ -44,7 +42,8 @@ triple_quoted_string = "\"\"\"((\"\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+))*\"\"\"" ; identifier = alpha | alpha alphanumeric ; -scoped_identifier = scoped_identifier WS "::" WS identifier | identifier ; +scope_op = ":" ":" ; +scoped_identifier = scoped_identifier WS scope_op WS identifier | identifier ; #Note that to prevent confilct with nested templates (T>) it is a nonterminal contructed as follows right_shift = ">" ">" ; @@ -93,7 +92,7 @@ comparator = "==" | "<=" | ">=" | "!=" | "<" | ">" ; expression = expression WS "<<" WS term | expression WS right_shift WS shiftand | shiftand ; shiftand = shiftand WS "-" WS term | shiftand WS "\+" WS term | term ; -term = term WS forward_slash WS factor | term WS "\*" WS factor | term WS "%" WS factor | factor ; +term = term WS "/" WS factor | term WS "\*" WS factor | term WS "%" WS factor | factor ; factor = "\+\+" WS unarad | unarad WS "\+\+" | "--" WS unarad | unarad WS "--" | "\+" WS unarad | "-" WS unarad | "!" WS unarad | "~" WS unarad | "\(" WS type WS "\)" WS unarad | "\*" WS unarad | "&" WS unarad | unarad ; unarad = number | scoped_identifier | scoped_identifier WS template_inst | function_call | bool | string | character | "\(" WS boolean_expression WS "\)" | access_operation | unarad WS "[" WS expression WS "]" ; number = integer | floating_literal ; @@ -104,10 +103,9 @@ declaration_statement = dec_type WS identifier WS "=" WS boolean_expression | de alphanumeric = alphanumeric numeric | alphanumeric alpha | numeric | alpha ; hexadecimal = "0x(1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)+" ; -sign = "\+|-" WS | ; -integer = sign numeric | sign hexadecimal ; -floating_literal = sign numeric "." numeric | sign numeric "." numeric alpha ; -bool = "true" | "false" | "True" | "False" ; +integer = numeric | hexadecimal ; +floating_literal = numeric "." numeric | numeric "." numeric alpha ; +bool = "true" | "false" ; character = "'(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|\"|Z|X|C|V|B|N|M|<|>|\?| )'" ; alpha = "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_)+" ; diff --git a/src/ASTData.cpp b/src/ASTData.cpp index 22fc30d..0869448 100644 --- a/src/ASTData.cpp +++ b/src/ASTData.cpp @@ -66,6 +66,8 @@ std::string ASTData::ASTTypeToString(ASTType type) { return "if_comp"; case simple_passthrough: return "simple_passthrough"; + case passthrough_params: + return "passthrough_params"; case function_call: return "function_call"; case value: diff --git a/src/ASTTransformation.cpp b/src/ASTTransformation.cpp index e7059d9..13bcebb 100644 --- a/src/ASTTransformation.cpp +++ b/src/ASTTransformation.cpp @@ -4,34 +4,36 @@ ASTTransformation::ASTTransformation(Importer *importerIn) { importer = importerIn; topScope = NULL; + builtin_trans_unit = new NodeTree("translation_unit", ASTData(translation_unit, Symbol("builtin", false))); + //Set up language level reserved identifier scope (only this, right now) languageLevelReservedWords["this"].push_back(new NodeTree("identifier", ASTData(identifier, Symbol("this", true), NULL))); //Set up language level special scope. (the final scope checked) //Note the NULL type - languageLevelOperators["+"].push_back(new NodeTree("function", ASTData(function, Symbol("+", true), NULL))); - languageLevelOperators["-"].push_back(new NodeTree("function", ASTData(function, Symbol("-", true), NULL))); - languageLevelOperators["*"].push_back(new NodeTree("function", ASTData(function, Symbol("*", true), NULL))); - languageLevelOperators["/"].push_back(new NodeTree("function", ASTData(function, Symbol("/", true), NULL))); - languageLevelOperators["%"].push_back(new NodeTree("function", ASTData(function, Symbol("%", true), NULL))); - languageLevelOperators["&"].push_back(new NodeTree("function", ASTData(function, Symbol("&", true), NULL))); - languageLevelOperators["--"].push_back(new NodeTree("function", ASTData(function, Symbol("--", true), NULL))); - languageLevelOperators["++"].push_back(new NodeTree("function", ASTData(function, Symbol("++", true), NULL))); - languageLevelOperators["=="].push_back(new NodeTree("function", ASTData(function, Symbol("==", true), new Type(boolean)))); - languageLevelOperators["!="].push_back(new NodeTree("function", ASTData(function, Symbol("!=", true), new Type(boolean)))); - languageLevelOperators["<="].push_back(new NodeTree("function", ASTData(function, Symbol("<=", true), new Type(boolean)))); - languageLevelOperators[">="].push_back(new NodeTree("function", ASTData(function, Symbol(">=", true), new Type(boolean)))); - languageLevelOperators["<"].push_back(new NodeTree("function", ASTData(function, Symbol("<", true), new Type(boolean)))); - languageLevelOperators[">"].push_back(new NodeTree("function", ASTData(function, Symbol(">", true), new Type(boolean)))); - languageLevelOperators["&&"].push_back(new NodeTree("function", ASTData(function, Symbol("&&", true), new Type(boolean)))); - languageLevelOperators["||"].push_back(new NodeTree("function", ASTData(function, Symbol("||", true), new Type(boolean)))); - languageLevelOperators["!"].push_back(new NodeTree("function", ASTData(function, Symbol("!", true), new Type(boolean)))); - languageLevelOperators["*="].push_back(new NodeTree("function", ASTData(function, Symbol("*=", true), NULL))); - languageLevelOperators["+="].push_back(new NodeTree("function", ASTData(function, Symbol("+=", true), NULL))); - languageLevelOperators["-="].push_back(new NodeTree("function", ASTData(function, Symbol("-=", true), NULL))); - languageLevelOperators["."].push_back(new NodeTree("function", ASTData(function, Symbol(".", true), NULL))); - languageLevelOperators["->"].push_back(new NodeTree("function", ASTData(function, Symbol("->", true), NULL))); - languageLevelOperators["[]"].push_back(new NodeTree("function", ASTData(function, Symbol("[]", true), NULL))); + languageLevelOperators["+"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("+", true), NULL)))); + languageLevelOperators["-"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("-", true), NULL)))); + languageLevelOperators["*"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("*", true), NULL)))); + languageLevelOperators["/"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("/", true), NULL)))); + languageLevelOperators["%"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("%", true), NULL)))); + languageLevelOperators["&"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("&", true), NULL)))); + languageLevelOperators["--"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("--", true), NULL)))); + languageLevelOperators["++"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("++", true), NULL)))); + languageLevelOperators["=="].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("==", true), new Type(boolean))))); + languageLevelOperators["!="].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("!=", true), new Type(boolean))))); + languageLevelOperators["<="].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("<=", true), new Type(boolean))))); + languageLevelOperators[">="].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol(">=", true), new Type(boolean))))); + languageLevelOperators["<"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("<", true), new Type(boolean))))); + languageLevelOperators[">"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol(">", true), new Type(boolean))))); + languageLevelOperators["&&"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("&&", true), new Type(boolean))))); + languageLevelOperators["||"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("||", true), new Type(boolean))))); + languageLevelOperators["!"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("!", true), new Type(boolean))))); + languageLevelOperators["*="].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("*=", true), NULL)))); + languageLevelOperators["+="].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("+=", true), NULL)))); + languageLevelOperators["-="].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("-=", true), NULL)))); + languageLevelOperators["."].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol(".", true), NULL)))); + languageLevelOperators["->"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("->", true), NULL)))); + languageLevelOperators["[]"].push_back(addToScope("~enclosing_scope", builtin_trans_unit, new NodeTree("function", ASTData(function, Symbol("[]", true), NULL)))); } ASTTransformation::~ASTTransformation() { @@ -40,7 +42,7 @@ ASTTransformation::~ASTTransformation() { //First pass defines all type_defs (objects and ailises), and if_comp/simple_passthrough NodeTree* ASTTransformation::firstPass(std::string fileName, NodeTree* parseTree) { - NodeTree* translationUnit = new NodeTree("translation_unit", ASTData(translation_unit)); + NodeTree* translationUnit = new NodeTree("translation_unit", ASTData(translation_unit, Symbol(fileName, false))); std::vector*> children = parseTree->getChildren(); importer->registerAST(fileName, translationUnit, parseTree); //Register ourselves with the importer. //This puts us in the scope and the list of ASTs that go through all the passes @@ -53,7 +55,7 @@ NodeTree* ASTTransformation::firstPass(std::string fileName, NodeTreegetChildren()[1]); else //It's not name = concatSymbolTree(i->getChildren()[0]); - NodeTree* firstDec = new NodeTree("type_def", ASTData(type_def, Symbol(name, true, name))); + NodeTree* firstDec = addToScope("~enclosing_scope", translationUnit, new NodeTree("type_def", ASTData(type_def, Symbol(name, true, name)))); //If this is a template, go ahead and set it up. Pass 2 needs templates set up so it can (partially) instantiate them. //So we give this typedef its name without any template types and make its type template_type, and point to this from node. //Then, when this template is instantiated, it will run transform on from with the types filled in. @@ -74,8 +76,8 @@ NodeTree* ASTTransformation::firstPass(std::string fileName, NodeTreegetDataRef()->scope["~enclosing_scope"].push_back(translationUnit); } else if (i->getDataRef()->getName() == "if_comp") { std::cout << "IF COMP" << std::endl; - NodeTree* newNode = new NodeTree(i->getDataRef()->getName(), ASTData(if_comp)); - newNode->addChild(new NodeTree("identifier", ASTData(identifier, Symbol(concatSymbolTree(i->getChildren()[0]),true)))); + NodeTree* newNode = addToScope("~enclosing_scope", translationUnit, new NodeTree(i->getDataRef()->getName(), ASTData(if_comp))); + newNode->addChild(addToScope("~enclosing_scope", newNode, new NodeTree("identifier", ASTData(identifier, Symbol(concatSymbolTree(i->getChildren()[0]),true))))); std::set skipChildren; skipChildren.insert(0); //Don't do the identifier. The identifier lookup will fail. That's why we do it here. newNode->addChildren(transformChildren(i->getChildren(), skipChildren, translationUnit, std::vector(), std::map())); @@ -89,7 +91,7 @@ NodeTree* ASTTransformation::firstPass(std::string fileName, NodeTreegetDataRef()->getName() == "import") { auto importChildren = i->getChildren(); std::string toImport = concatSymbolTree(importChildren[0]); - auto importNode = new NodeTree("import", ASTData(import, Symbol(toImport, true))); + auto importNode = addToScope("~enclosing_scope", translationUnit, new NodeTree("import", ASTData(import, Symbol(toImport, true)))); translationUnit->addChild(importNode); //Do the imported file too NodeTree* outsideTranslationUnit = importer->importFirstPass(toImport + ".krak"); @@ -185,13 +187,13 @@ void ASTTransformation::secondPassDoClassInsides(NodeTree* typeDef, std //This function may need to partially instantiate a class template NodeTree* ASTTransformation::secondPassDeclaration(NodeTree* from, NodeTree* scope, std::map templateTypeReplacements) { //Check here for method call (an error here) - NodeTree* decStmt = new NodeTree("declaration_statement", ASTData(declaration_statement)); + NodeTree* decStmt = addToScope("~enclosing_scope", scope, new NodeTree("declaration_statement", ASTData(declaration_statement))); std::string newIdentifierStr = concatSymbolTree(from->getChildren()[1]); Type* identifierType = typeFromTypeNode(from->getChildren()[0], scope, templateTypeReplacements); std::cout << "Declaring an identifier " << newIdentifierStr << " to be of type " << identifierType->toString() << std::endl; - NodeTree* newIdentifier = new NodeTree("identifier", ASTData(identifier, Symbol(newIdentifierStr, true), identifierType)); - scope->getDataRef()->scope[newIdentifierStr].push_back(newIdentifier); - decStmt->getDataRef()->scope["~enclosing_scope"].push_back(scope); + NodeTree* newIdentifier = addToScope("~enclosing_scope", decStmt, new NodeTree("identifier", ASTData(identifier, Symbol(newIdentifierStr, true), identifierType))); + //scope->getDataRef()->scope[newIdentifierStr].push_back(newIdentifier); + addToScope(newIdentifierStr, newIdentifier, scope); // NEW WAY! decStmt->addChild(newIdentifier); return decStmt; @@ -206,8 +208,8 @@ NodeTree* ASTTransformation::secondPassFunction(NodeTree* from, if (children[0]->getData().getName() == "template_dec") { functionName = concatSymbolTree(children[2]); functionDef = new NodeTree("function", ASTData(function, Symbol(functionName, true), new Type(template_type, from))); - scope->getDataRef()->scope[functionName].push_back(functionDef); - functionDef->getDataRef()->scope["~enclosing_scope"].push_back(scope); + addToScope("~enclosing_scope", scope, functionDef); + addToScope(functionName, functionDef, scope); std::map yetToBeInstantiatedTemplateTypes; //So that template types (like T) that have not been placed yet are found and given //a special Type() - baseType = template_type_type for (auto i : slice(children[0]->getChildren(), 1, -1, 2)) {//skip commas @@ -229,8 +231,8 @@ NodeTree* ASTTransformation::secondPassFunction(NodeTree* from, } functionName = concatSymbolTree(children[1]); functionDef = new NodeTree("function", ASTData(function, Symbol(functionName, true), typeFromTypeNode(children[0], scope, templateTypeReplacements))); - scope->getDataRef()->scope[functionName].push_back(functionDef); - functionDef->getDataRef()->scope["~enclosing_scope"].push_back(scope); + addToScope("~enclosing_scope", scope, functionDef); + addToScope(functionName, functionDef, scope); //We only do the parameter nodes. We don't do the body yet, as this is the secondPass auto transChildren = transformChildren(slice(children,2,-2), std::set(), functionDef, std::vector(), templateTypeReplacements); @@ -395,8 +397,11 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree } newNode->getDataRef()->valueType = objectType; //Type is self-referential since this is the definition } + // ?? why not this? //scope->getDataRef()->scope[typeAlias].push_back(newNode); - newNode->getDataRef()->scope["~enclosing_scope"].push_back(scope); + //newNode->getDataRef()->scope["~enclosing_scope"].push_back(scope); + addToScope("~enclosing_scope", scope, newNode); + //Templates are done here. No need to go farther if (children[0]->getData().getName() == "template_dec") @@ -408,8 +413,8 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree if (children[0]->getData().getName() == "template_dec") { functionName = concatSymbolTree(children[2]); newNode = new NodeTree(name, ASTData(function, Symbol(functionName, true), new Type(template_type, from))); - scope->getDataRef()->scope[functionName].push_back(newNode); - newNode->getDataRef()->scope["~enclosing_scope"].push_back(scope); + addToScope(functionName, newNode, scope); + addToScope("~enclosing_scope", scope, newNode); std::map yetToBeInstantiatedTemplateTypes; //So that template types (like T) that have not been placed yet are found and given //a special Type() - baseType = template_type_type for (auto i : slice(children[0]->getChildren(), 1, -1, 2)) //skip commas @@ -431,8 +436,8 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree newNode = new NodeTree(name, ASTData(function, Symbol(functionName, true), typeFromTypeNode(children[0], scope, templateTypeReplacements))); skipChildren.insert(0); skipChildren.insert(1); - scope->getDataRef()->scope[functionName].push_back(newNode); - newNode->getDataRef()->scope["~enclosing_scope"].push_back(scope); + addToScope(functionName, newNode, scope); + addToScope("~enclosing_scope", scope, newNode); scope = newNode; // auto transChildren = transformChildren(children, skipChildren, scope, types); @@ -446,7 +451,7 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree std::cout << "finished function (kinda, not children) " << functionName << std::endl; } else if (name == "code_block") { newNode = new NodeTree(name, ASTData(code_block)); - newNode->getDataRef()->scope["~enclosing_scope"].push_back(scope); + addToScope("~enclosing_scope", scope, newNode); scope = newNode; } else if (name == "typed_parameter") { //newNode = transform(children[1]); //Transform to get the identifier @@ -454,8 +459,8 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree std::cout << "Doing typed parameter " << parameterName << std::endl; //std::string typeString = concatSymbolTree(children[0]);//Get the type (left child) and set our new identifer to be that type newNode = new NodeTree("identifier", ASTData(identifier, Symbol(parameterName, true), typeFromTypeNode(children[0], scope, templateTypeReplacements))); - scope->getDataRef()->scope[parameterName].push_back(newNode); - newNode->getDataRef()->scope["~enclosing_scope"].push_back(scope); + addToScope(parameterName, newNode, scope); + addToScope("~enclosing_scope", scope, newNode); std::cout << "Done doing typed_parameter " << parameterName << std::endl; return newNode; } else if (name == "boolean_expression" || name == "and_boolean_expression" || name == "bool_exp") { @@ -476,6 +481,7 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree // newNode->addChildren(transformedChildren); } else { //std::cout << children.size() << std::endl; + // XXX What the heck is this if (children.size() == 0) return new NodeTree(); return transform(children[0], scope, types, templateTypeReplacements); //Just a promoted term, so do child @@ -539,6 +545,7 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree return transform(children[0], scope, types, templateTypeReplacements); //Just a promoted child, so do it instead } } else if (name == "statement") { + //XXX newNode = new NodeTree(name, ASTData(statement)); } else if (name == "if_statement") { newNode = new NodeTree(name, ASTData(if_statement)); @@ -578,8 +585,9 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree Type* identifierType = typeFromTypeNode(children[0], scope, templateTypeReplacements); std::cout << "Declaring an identifier " << newIdentifierStr << " to be of type " << identifierType->toString() << std::endl; NodeTree* newIdentifier = new NodeTree("identifier", ASTData(identifier, Symbol(newIdentifierStr, true), identifierType)); - scope->getDataRef()->scope[newIdentifierStr].push_back(newIdentifier); - newNode->getDataRef()->scope["~enclosing_scope"].push_back(scope); + addToScope(newIdentifierStr, newIdentifier, scope); + addToScope("~enclosing_scope", scope, newNode); + addToScope("~enclosing_scope", newNode, newIdentifier); newNode->addChild(newIdentifier); if (children.size() > 2 && concatSymbolTree(children[2]) == ".") { @@ -610,10 +618,17 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree return newNode; } else if (name == "if_comp") { newNode = new NodeTree(name, ASTData(if_comp)); - newNode->addChild(new NodeTree("identifier", ASTData(identifier, Symbol(concatSymbolTree(children[0]),true)))); + newNode->addChild(addToScope("~enclosing_scope", scope, new NodeTree("identifier", ASTData(identifier, Symbol(concatSymbolTree(children[0]),true))))); + std::cout << "XXX scope is " << scope << std::endl; + addToScope("~enclosing_scope", scope, newNode); skipChildren.insert(0); //Don't do the identifier. The identifier lookup will fail. That's why we do it here. } else if (name == "simple_passthrough") { newNode = new NodeTree(name, ASTData(simple_passthrough)); + addToScope("~enclosing_scope", scope, newNode); + std::cout << "XXX scope is " << scope << std::endl; + } else if (name == "passthrough_params") { + newNode = new NodeTree(name, ASTData(passthrough_params)); + addToScope("~enclosing_scope", scope, newNode); } else if (name == "function_call") { std::string functionCallName = concatSymbolTree(children[0]); newNode = new NodeTree(functionCallName, ASTData(function_call, Symbol(functionCallName, true))); @@ -638,6 +653,7 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree } else if (name == "type") { std::string theConcat = concatSymbolTree(from); //We have no symbol, so this will concat our children newNode = new NodeTree(name, ASTData(value, Symbol(theConcat, true), typeFromTypeNode(from, scope, templateTypeReplacements))); + addToScope("~enclosing_scope", scope, newNode); } else if (name == "number") { return transform(children[0], scope, types, templateTypeReplacements); } else if (name == "integer") { @@ -1041,7 +1057,7 @@ std::vector*> ASTTransformation::scopeLookup(NodeTree } std::vector*> ASTTransformation::scopeLookup(NodeTree* scope, std::string lookup, bool includeModules, std::vector*> visited) { - std::cout << "Scp][e looking up " << lookup << std::endl; + std::cout << "Scp]|[e looking up " << lookup << std::endl; // Don't visit this node again when looking for the smae lookup. Note that we don't prevent coming back for the scope operator, as that should be able to come back. visited.push_back(scope); //We first check to see if it's one of the special reserved identifiers (only this, for now) and return early if it is. @@ -1241,9 +1257,9 @@ Type* ASTTransformation::typeFromTypeNode(NodeTree* typeNode, NodeTreegetDataRef()->scope[fullyInstantiatedName].push_back(typeDefinition); // We put it in the scope of the template so that it can find itself (as it's scope is its template definition) - templateDefinition->getDataRef()->scope[fullyInstantiatedName].push_back(typeDefinition); + addToScope(fullyInstantiatedName, typeDefinition, templateDefinition); //Note that the instantiated template's scope is the template's definition. - typeDefinition->getDataRef()->scope["~enclosing_scope"].push_back(templateDefinition); + addToScope("~enclosing_scope", templateDefinition, typeDefinition); // We only partially instantiate templates no matter what now // They are all fully instantiated in the loop at the end of the 4th pass @@ -1326,11 +1342,13 @@ NodeTree* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec skipChildren.insert(1); skipChildren.insert(2); //scope->getDataRef()->scope[fullyInstantiatedName].push_back(instantiatedFunction); - instantiatedFunction->getDataRef()->scope["~enclosing_scope"].push_back(templateDefinition->getDataRef()->scope["~enclosing_scope"][0]); //Instantiated Template Function's scope is it's template's definition's scope + //instantiatedFunction->getDataRef()->scope["~enclosing_scope"].push_back(templateDefinition->getDataRef()->scope["~enclosing_scope"][0]); //Instantiated Template Function's scope is it's template's definition's scope + addToScope("~enclosing_scope", templateDefinition->getDataRef()->scope["~enclosing_scope"][0], instantiatedFunction); // Arrrrrgh this has a hard time working because the functions will need to see their parameter once they are emitted as C. // HAHAHAHAHA DOESN'T MATTER ALL ONE C FILE NOW, swap back to old way auto templateTopScope = getUpperTranslationUnit(templateDefinition); - templateTopScope->getDataRef()->scope[fullyInstantiatedName].push_back(instantiatedFunction); + //templateTopScope->getDataRef()->scope[fullyInstantiatedName].push_back(instantiatedFunction); + addToScope(fullyInstantiatedName, instantiatedFunction, templateTopScope); templateTopScope->addChild(instantiatedFunction); // Add this object the the highest scope's //topScope->getDataRef()->scope[fullyInstantiatedName].push_back(instantiatedFunction); //topScope->addChild(instantiatedFunction); //Add this object the the highest scope's @@ -1339,7 +1357,12 @@ NodeTree* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec instantiatedFunction->addChildren(transformChildren(templateSyntaxTree->getChildren(), skipChildren, instantiatedFunction, std::vector(), newTemplateTypeReplacement)); std::cout << "Fully Instantiated function " << functionName << " to " << fullyInstantiatedName << std::endl; - return instantiatedFunction; } +NodeTree* ASTTransformation::addToScope(std::string name, NodeTree* toAdd, NodeTree* addTo) { + addTo->getDataRef()->scope[name].push_back(toAdd); + return addTo; +} + + diff --git a/src/CGenerator.cpp b/src/CGenerator.cpp index dd50b30..7e4b474 100644 --- a/src/CGenerator.cpp +++ b/src/CGenerator.cpp @@ -11,13 +11,6 @@ void CGenerator::generateCompSet(std::map*> ASTs, //Generate an entire set of files std::string buildString = "#!/bin/sh\ncc -std=c99 "; std::cout << "\n\n =====GENERATE PASS===== \n\n" << std::endl; - // This is made earlier now, as we want to put the dot files here too - //if (mkdir(("./" + outputName).c_str(), 0755)) { - //std::cerr << "\n\n =====GENERATE PASS===== \n\n" << std::endl; - //std::cerr << "Could not make directory " << outputName << std::endl; - ////throw "could not make directory "; - //} - std::cout << "\n\nGenerate pass for: " << outputName << std::endl; buildString += outputName + ".c "; std::ofstream outputCFile, outputHFile; @@ -51,7 +44,7 @@ std::string CGenerator::tabs() { std::string CGenerator::generateClassStruct(NodeTree* from) { auto data = from->getData(); auto children = from->getChildren(); - std::string objectString = "struct __struct_dummy_" + CifyName(data.symbol.getName()) + "__ {\n"; + std::string objectString = "struct __struct_dummy_" + scopePrefix(from) + CifyName(data.symbol.getName()) + "__ {\n"; tabLevel++; for (int i = 0; i < children.size(); i++) { std::cout << children[i]->getName() << std::endl; @@ -73,7 +66,9 @@ std::string CGenerator::generateAliasChains(std::maptype == type_def && declarationData->valueType->typeDefinition != declaration && declarationData->valueType->typeDefinition == definition) { - output += "typedef " + CifyName(definition->getDataRef()->symbol.getName()) + " " + CifyName(declarationData->symbol.getName()) + ";\n"; + output += "typedef " + + scopePrefix(definition) + CifyName(definition->getDataRef()->symbol.getName()) + " " + + scopePrefix(declaration) + CifyName(declarationData->symbol.getName()) + ";\n"; // Recursively add the ones that depend on this one output += generateAliasChains(ASTs, declaration); } @@ -178,7 +173,7 @@ std::pair CGenerator::generateTranslationUnit(std::str ASTData declarationData = declaration->getData(); switch(declarationData.type) { case identifier: - variableDeclarations += ValueTypeToCType(declarationData.valueType) + " " + declarationData.symbol.getName() + "; /*identifier*/\n"; + variableDeclarations += ValueTypeToCType(declarationData.valueType) + " " + scopePrefix(declaration) + declarationData.symbol.getName() + "; /*identifier*/\n"; variableExternDeclarations += "extern " + ValueTypeToCType(declarationData.valueType) + " " + declarationData.symbol.getName() + "; /*extern identifier*/\n"; break; case function: @@ -196,9 +191,12 @@ std::pair CGenerator::generateTranslationUnit(std::str parameters += ValueTypeToCType(decChildren[j]->getData().valueType) + " " + generate(decChildren[j], nullptr); nameDecoration += "_" + ValueTypeToCTypeDecoration(decChildren[j]->getData().valueType); } - functionPrototypes += CifyName(declarationData.symbol.getName() + nameDecoration) + "(" + parameters + "); /*func*/\n"; + functionPrototypes += scopePrefix(declaration) + + CifyName(declarationData.symbol.getName() + nameDecoration) + + "(" + parameters + "); /*func*/\n"; // generate function - std::cout << "Generating " << CifyName(declarationData.symbol.getName()) << std::endl; + std::cout << "Generating " << scopePrefix(declaration) + + CifyName(declarationData.symbol.getName()) << std::endl; functionDefinitions += generate(declaration, nullptr); } } @@ -213,10 +211,14 @@ std::pair CGenerator::generateTranslationUnit(std::str if (declarationData.valueType->typeDefinition) continue; // Aliases of objects are done with the thing it alises // Otherwise, we're actually a renaming of a primitive, can generate here - plainTypedefs += "typedef " + ValueTypeToCType(declarationData.valueType) + " " + CifyName(declarationData.symbol.getName()) + ";\n"; + plainTypedefs += "typedef " + ValueTypeToCType(declarationData.valueType) + " " + + scopePrefix(declaration) + + CifyName(declarationData.symbol.getName()) + ";\n"; plainTypedefs += generateAliasChains(ASTs, declaration); } else { - plainTypedefs += "typedef struct __struct_dummy_" + CifyName(declarationData.symbol.getName()) + "__ " + CifyName(declarationData.symbol.getName()) + ";\n"; + plainTypedefs += "typedef struct __struct_dummy_" + + scopePrefix(declaration) + CifyName(declarationData.symbol.getName()) + "__ " + + scopePrefix(declaration) + CifyName(declarationData.symbol.getName()) + ";\n"; functionPrototypes += "/* Method Prototypes for " + declarationData.symbol.getName() + " */\n"; // We use a seperate string for this because we only include it if this is the file we're defined in std::string objectFunctionDefinitions = "/* Method Definitions for " + declarationData.symbol.getName() + " */\n"; @@ -278,7 +280,8 @@ std::string CGenerator::generate(NodeTree* from, NodeTree* enc std::string preName; if (enclosingObject && enclosingObject->getDataRef()->scope.find(data.symbol.getName()) != enclosingObject->getDataRef()->scope.end()) preName += "this->"; - return preName + CifyName(data.symbol.getName()); //Cifying does nothing if not an operator overload + // we're scope prefixing EVERYTHING + return preName + scopePrefix(from) + CifyName(data.symbol.getName()); //Cifying does nothing if not an operator overload } case function: { @@ -292,7 +295,7 @@ std::string CGenerator::generate(NodeTree* from, NodeTree* enc parameters += ValueTypeToCType(children[j]->getData().valueType) + " " + generate(children[j], enclosingObject); nameDecoration += "_" + ValueTypeToCTypeDecoration(children[j]->getData().valueType); } - output += CifyName(data.symbol.getName() + nameDecoration) + "(" + parameters + ")\n" + generate(children[children.size()-1], enclosingObject); + output += scopePrefix(from) + CifyName(data.symbol.getName() + nameDecoration) + "(" + parameters + ")\n" + generate(children[children.size()-1], enclosingObject); return output; } case code_block: @@ -315,7 +318,7 @@ std::string CGenerator::generate(NodeTree* from, NodeTree* enc continue; if (typeDefinition->getDataRef()->scope.find("destruct") == typeDefinition->getDataRef()->scope.end()) continue; - destructorString += tabs() + CifyName(typeDefinition->getDataRef()->symbol.getName()) + destructorString += tabs() + scopePrefix(from) + CifyName(typeDefinition->getDataRef()->symbol.getName()) + "__" + "destruct" + "(&" + generate(identifier, enclosingObject) + ");\n";//Call the destructor } } @@ -370,7 +373,9 @@ std::string CGenerator::generate(NodeTree* from, NodeTree* enc } else return ValueTypeToCType(children[0]->getData().valueType) + " " + generate(children[0], enclosingObject) + " = " + generate(children[1], enclosingObject) + ";"; case if_comp: - if (generate(children[0], enclosingObject) == generatorString) + // Lol, this doesn't work because the string gets prefixed now + //if (generate(children[0], enclosingObject) == generatorString) + if (children[0]->getDataRef()->symbol.getName() == generatorString) return generate(children[1], enclosingObject); return ""; case simple_passthrough: @@ -415,7 +420,9 @@ std::string CGenerator::generate(NodeTree* from, NodeTree* enc std::cout << "Decorating (in access-should be object) " << name << " " << functionDefChildren.size() << std::endl; for (int i = 0; i < (functionDefChildren.size() > 0 ? functionDefChildren.size()-1 : 0); i++) nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType); -/*HERE*/ return CifyName(unaliasedTypeDef->getDataRef()->symbol.getName()) +"__" + CifyName(functionName + nameDecoration) + "(" + (name == "." ? "&" : "") + generate(children[1], enclosingObject) + ","; + // Note that we only add scoping to the object, as this specifies our member function too +/*HERE*/ return scopePrefix(unaliasedTypeDef) + CifyName(unaliasedTypeDef->getDataRef()->symbol.getName()) +"__" + + CifyName(functionName + nameDecoration) + "(" + (name == "." ? "&" : "") + generate(children[1], enclosingObject) + ","; //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 } else { @@ -439,11 +446,13 @@ std::string CGenerator::generate(NodeTree* from, NodeTree* enc nameDecoration += "_" + ValueTypeToCTypeDecoration(functionDefChildren[i]->getData().valueType); //Check to see if we're inside of an object and this is a method call bool isSelfObjectMethod = enclosingObject && contains(enclosingObject->getChildren(), children[0]); - if (isSelfObjectMethod) - output += CifyName(enclosingObject->getDataRef()->symbol.getName()) +"__"; -/*HERE*/ output += CifyName(name + nameDecoration) + "("; - if (isSelfObjectMethod) + if (isSelfObjectMethod) { + output += scopePrefix(children[0]) + CifyName(enclosingObject->getDataRef()->symbol.getName()) +"__"; + output += CifyName(name + nameDecoration) + "("; output += children.size() > 1 ? "this," : "this"; + } else { + output += scopePrefix(children[0]) + CifyName(name + nameDecoration) + "("; + } } } else { //This part handles cases where our definition isn't the function definition (that is, it is probabally the return from another function) @@ -491,7 +500,7 @@ std::string CGenerator::generateObjectMethod(NodeTree* enclosingObject, parameters += ", " + ValueTypeToCType(children[i]->getData().valueType) + " " + generate(children[i]); nameDecoration += "_" + ValueTypeToCTypeDecoration(children[i]->getData().valueType); } - std::string functionSignature = "\n" + ValueTypeToCType(data.valueType) + " " + CifyName(enclosingObject->getDataRef()->symbol.getName()) +"__" + std::string functionSignature = "\n" + ValueTypeToCType(data.valueType) + " " + scopePrefix(from) + CifyName(enclosingObject->getDataRef()->symbol.getName()) +"__" + CifyName(data.symbol.getName()) + nameDecoration + "(" + ValueTypeToCType(&enclosingObjectType) + " this" + parameters + ")"; *functionPrototype += functionSignature + ";\n"; @@ -506,7 +515,7 @@ std::string CGenerator::ValueTypeToCTypeThingHelper(Type *type, std::string ptrS switch (type->baseType) { case none: if (type->typeDefinition) - return_type = CifyName(type->typeDefinition->getDataRef()->symbol.getName()); + return_type = scopePrefix(type->typeDefinition) + CifyName(type->typeDefinition->getDataRef()->symbol.getName()); else return_type = "none"; break; @@ -589,4 +598,17 @@ std::string CGenerator::CifyName(std::string name) { } return name; } +// Generate the scope prefix, that is "file_class_" for a method, etc +// What do we still need to handle? Packages! But we don't have thoes yet.... +std::string CGenerator::scopePrefix(NodeTree* from) { + //return ""; + std::string suffix = "_scp_"; + ASTData data = from->getData(); + if (data.type == translation_unit) + return CifyName(data.symbol.getName()) + suffix; + // so we do prefixing for stuff that c doesn't already scope: + // different files. That's it for now. Methods are already lowered correctly with their parent object, + // that parent object will get scoped. When we add a package system, we'll have to then add their scoping here + return scopePrefix(from->getDataRef()->scope["~enclosing_scope"][0]); +} diff --git a/src/Importer.cpp b/src/Importer.cpp index 90b9fbe..79f9f1e 100644 --- a/src/Importer.cpp +++ b/src/Importer.cpp @@ -18,7 +18,7 @@ Importer::Importer(Parser* parserIn, std::vector includePaths, std: removeSymbols.push_back(Symbol("\\(", true)); removeSymbols.push_back(Symbol("\\)", true)); //removeSymbols.push_back(Symbol("::", true)); - removeSymbols.push_back(Symbol(":", true)); + //removeSymbols.push_back(Symbol(":", true)); removeSymbols.push_back(Symbol(";", true)); removeSymbols.push_back(Symbol("SEMI", false)); removeSymbols.push_back(Symbol("{", true)); @@ -30,13 +30,13 @@ Importer::Importer(Parser* parserIn, std::vector includePaths, std: removeSymbols.push_back(Symbol("if", true)); removeSymbols.push_back(Symbol("while", true)); removeSymbols.push_back(Symbol("__if_comp__", true)); - removeSymbols.push_back(Symbol("__simple_passthrough__", true)); + removeSymbols.push_back(Symbol("simple_passthrough", true)); removeSymbols.push_back(Symbol("comp_simple_passthrough", true)); removeSymbols.push_back(Symbol("typedef", true)); removeSymbols.push_back(Symbol("template", true)); removeSymbols.push_back(Symbol("\\|", true)); - //collapseSymbols.push_back(Symbol("scoped_identifier", false)); + collapseSymbols.push_back(Symbol("opt_param_assign_list", false)); collapseSymbols.push_back(Symbol("opt_typed_parameter_list", false)); collapseSymbols.push_back(Symbol("opt_parameter_list", false)); collapseSymbols.push_back(Symbol("opt_import_list", false)); diff --git a/stdlib/io.krak b/stdlib/io.krak index a5d7b60..0fc8a3e 100644 --- a/stdlib/io.krak +++ b/stdlib/io.krak @@ -1,6 +1,6 @@ import string:*; -__if_comp__ __C__ __simple_passthrough__ """ +__if_comp__ __C__ simple_passthrough """ #include """ @@ -10,7 +10,7 @@ __if_comp__ __C__ __simple_passthrough__ """ |void| print(|char*| toPrint) { __if_comp__ __C__ { - __simple_passthrough__ """ + simple_passthrough(toPrint = toPrint::) """ printf(toPrint); """ } @@ -32,7 +32,7 @@ __if_comp__ __C__ __simple_passthrough__ """ |void| print(|int| toPrint) { __if_comp__ __C__ { - __simple_passthrough__ """ + simple_passthrough(toPrint = toPrint::) """ printf("%d", toPrint); """ } @@ -46,7 +46,7 @@ __if_comp__ __C__ __simple_passthrough__ """ |void| print(|float| toPrint) { __if_comp__ __C__ { - __simple_passthrough__ """ + simple_passthrough(toPrint = toPrint::) """ printf("%f", toPrint); """ } @@ -55,7 +55,7 @@ __if_comp__ __C__ __simple_passthrough__ """ |void| print(|double| toPrint) { __if_comp__ __C__ { - __simple_passthrough__ """ + simple_passthrough(toPrint = toPrint::) """ printf("%f", toPrint); """ } diff --git a/stdlib/math.krak b/stdlib/math.krak index d59cd17..a530215 100644 --- a/stdlib/math.krak +++ b/stdlib/math.krak @@ -1,4 +1,4 @@ -__if_comp__ __C__ __simple_passthrough__ """ +__if_comp__ __C__ simple_passthrough """ #include """ @@ -16,11 +16,11 @@ __if_comp__ __C__ __simple_passthrough__ """ { |double| ans = 0; __if_comp__ __C__{ - __simple_Passthrough__ """ + simple_passthrough(arg = arg : ans = ans :) """ ans = atan(arg); """ }//end C wrapper - + return ans; }//end atan function @@ -28,11 +28,11 @@ __if_comp__ __C__ __simple_passthrough__ """ { |double| ans = 0; __if_comp__ __C__{ - __simple_Passthrough__ """ + simple_passthrough(x = x, y = y : ans = ans :) """ ans = atan2(x,y); """ }//end C wrapper - + return ans; }//end atan2 function @@ -40,11 +40,11 @@ __if_comp__ __C__ __simple_passthrough__ """ { |double| ans = 0; __if_comp__ __C__{ - __simple_Passthrough__ """ + simple_passthrough(arg = arg : ans = ans :) """ ans = acos(arg); """ }//end C wrapper - + return ans; }//end acos function @@ -52,11 +52,11 @@ __if_comp__ __C__ __simple_passthrough__ """ { |double| ans = 0; __if_comp__ __C__{ - __simple_Passthrough__ """ + simple_passthrough(arg = arg : ans = ans :) """ ans = asin(arg); """ }//end C wrapper - + return ans; }//end asin function @@ -64,11 +64,11 @@ __if_comp__ __C__ __simple_passthrough__ """ { |double| ans = 0; __if_comp__ __C__{ - __simple_Passthrough__ """ + simple_passthrough(arg = arg : ans = ans :) """ ans = tan(arg); """ }//end C wrapper - + return ans; }//end tan function @@ -76,11 +76,11 @@ __if_comp__ __C__ __simple_passthrough__ """ { |double| ans = 0; __if_comp__ __C__{ - __simple_Passthrough__ """ + simple_passthrough(arg = arg : ans = ans :) """ ans = cos(arg); """ }//end C wrapper - + return ans; }//end cos function @@ -88,11 +88,11 @@ __if_comp__ __C__ __simple_passthrough__ """ { |double| ans = 0; __if_comp__ __C__{ - __simple_Passthrough__ """ + simple_passthrough(arg = arg : ans = ans :) """ ans = sin(arg); """ }//end C wrapper - + return ans; }//end sin function diff --git a/stdlib/mem.krak b/stdlib/mem.krak index 406592a..a8d87ce 100644 --- a/stdlib/mem.krak +++ b/stdlib/mem.krak @@ -1,4 +1,4 @@ -__if_comp__ __C__ __simple_passthrough__ """ +__if_comp__ __C__ simple_passthrough """ #include """ @@ -7,7 +7,7 @@ __if_comp__ __C__ __simple_passthrough__ """ template |T*| malloc(|int| size) { |T*| memPtr = 0; __if_comp__ __C__ { - __simple_passthrough__ """ + simple_passthrough( size = size : memPtr = memPtr :) """ memPtr = malloc(size); """ } @@ -16,7 +16,7 @@ template |T*| malloc(|int| size) { template |void| free(|T*| memPtr) { __if_comp__ __C__ { - __simple_passthrough__ """ + simple_passthrough(memPtr = memPtr ::) """ free(memPtr); """ } @@ -26,7 +26,7 @@ template |int| sizeof() { |int| result = 0; |T| testObj; __if_comp__ __C__ { - __simple_passthrough__ """ + simple_passthrough(testObj = testObj : result = result:) """ result = sizeof(testObj); """ } @@ -55,10 +55,10 @@ template |void| delete(|T*| toDelete, |int| itemCount) { /* We specilize on the trait Destructable to decide on whether or not the destructor should be called */ template |void| delete(|T*| toDelete) { - free(toDelete); + free(toDelete); } template |void| delete(|T*| toDelete) { toDelete->destruct(); - free(toDelete); + free(toDelete); }