From eae538907dbac973443647fbfd93aebdb17ff773 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sun, 20 Jul 2014 20:42:26 -0700 Subject: [PATCH] Fixed some mem things, found an odd parsing bug where a // comment before a function definition at top level does not parse. Deferring for now. --- krakenGrammer.kgm | 4 ---- src/ASTTransformation.cpp | 14 ++++++++++++-- stdlib/mem.krak | 16 +++++++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/krakenGrammer.kgm b/krakenGrammer.kgm index e7cb9de..1e735b0 100644 --- a/krakenGrammer.kgm +++ b/krakenGrammer.kgm @@ -7,10 +7,6 @@ type = type WS "\*" | "void" | "int" | "float" | "double" | "char" | identifier template_inst = "<" WS type_list WS ">" ; type_list = type_list WS "," WS type | type ; -#What does that even mean? -#some -# -# template_dec = "template" WS "<" WS template_param_list WS ">" ; template_param_list = template_param_list WS "," WS template_param | template_param ; template_param = identifier WS traits | identifier ; diff --git a/src/ASTTransformation.cpp b/src/ASTTransformation.cpp index a5cd7bd..688ba8d 100644 --- a/src/ASTTransformation.cpp +++ b/src/ASTTransformation.cpp @@ -331,13 +331,13 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree if (types.size()) { newNode = functionLookup(scope, lookupName, types); if (newNode == NULL) { - std::cout << "scope lookup error! Could not find " << lookupName << " in identifier " << std::endl; + std::cout << "scope lookup error! Could not find " << lookupName << " in identifier (functionLookup)" << std::endl; throw "LOOKUP ERROR: " + lookupName; } } else { auto possibleMatches = scopeLookup(scope, lookupName); if (!possibleMatches.size()) { - std::cout << "scope lookup error! Could not find " << lookupName << " in identifier " << std::endl; + std::cout << "scope lookup error! Could not find " << lookupName << " in identifier (scopeLookup)" << std::endl; throw "LOOKUP ERROR: " + lookupName; } newNode = possibleMatches[0]; @@ -883,6 +883,10 @@ NodeTree* ASTTransformation::templateFunctionLookup(NodeTree* for (auto i : possibleMatches) { std::cout << "Possibility " << index++ << std::endl; NodeTree* templateSyntaxTree = i->getDataRef()->valueType->templateDefinition; + if (!templateSyntaxTree) { + std::cout << "Not a template, skipping" << std::endl; + continue; + } auto nameTraitsPairs = makeTemplateNameTraitPairs(templateSyntaxTree->getChildren()[0]); //Check if sizes match between the placeholder and actual template types @@ -975,6 +979,12 @@ std::map ASTTransformation::makeTemplateFunctionTypeMap(Node } std::vector*> ASTTransformation::scopeLookup(NodeTree* scope, std::string lookup) { + //We first check to see if it's one of the special reserved identifiers (only this, for now) and return early if it is. + auto LLElementIterator = languageLevelReservedWords.find(lookup); + if (LLElementIterator != languageLevelReservedWords.end()) { + std::cout << "found it at language level as reserved word." << std::endl; + return LLElementIterator->second; + } std::vector*> matches; std::map*>> scopeMap = scope->getDataRef()->scope; auto possibleMatches = scopeMap.find(lookup); diff --git a/stdlib/mem.krak b/stdlib/mem.krak index c4b30c5..48b0505 100644 --- a/stdlib/mem.krak +++ b/stdlib/mem.krak @@ -22,6 +22,7 @@ void free(char* memPtr) { } } +/* we have a template version so we don't have to cast */ template void free(T* memPtr) { __if_comp__ __C__ { __simple_passthrough__ """ @@ -41,7 +42,6 @@ template int sizeof() { return result; } - template T* new(int count) { return malloc( sizeof() * count ); } @@ -50,18 +50,24 @@ template T* new() { return new(1); } -template void delete(T* toDelete, int itemDestructCount) { +/* We specilize on the trait Destructable to decide on whether or not the destructor should be called */ +template void delete(T* toDelete, int itemCount) { + delete(toDelete); +} + +template void delete(T* toDelete, int itemCount) { for (int i = 0; i < itemDestructCount; i++;) toDelete[i].destruct(); delete(toDelete); } +/* We specilize on the trait Destructable to decide on whether or not the destructor should be called */ template void delete(T* toDelete) { - delete(toDelete, true); + free(toDelete); } -template void delete(T* toDelete, bool destruct) { +template void delete(T* toDelete) { if (destruct) toDelete->destruct(); - free(toDelete); + free(toDelete); }