Verified Commit 300a410e authored by Camil Staps's avatar Camil Staps 🚀

Add ABCInstructionEntry

parent a5e772d1
......@@ -12,7 +12,8 @@ from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
from Type import :: Type, :: TypeVar, :: TVAssignment, :: TypeDef,
:: TypeContext, :: TypeRestriction, :: Priority, class print(..)
from Cloogle import :: FunctionKind, :: SyntaxExample, :: CleanLangReportLocation
from Cloogle import :: FunctionKind, :: SyntaxExample,
:: CleanLangReportLocation, :: ABCArgument
from Doc import :: FunctionDoc, :: TypeDoc, :: ClassDoc, :: ModuleDoc
from DB import :: DB, :: Entry, :: Index
......@@ -31,6 +32,7 @@ from TypeTree import :: TypeTree
, apps :: ![Index] //* Entries in app modules
, builtins :: ![Index] //* Entries in Clean core
, syntax :: ![Index] //* SyntaxEntries
, abc_instrs :: ![Index] //* ABCInstructionEntries
, library_map :: !Map Name [Index] //* Entries by library name
, module_map :: !Map Name [Index] //* Entries by module name
, derive_map :: !Map Name [Index] //* DeriveEntries by generic name
......@@ -52,6 +54,7 @@ from TypeTree import :: TypeTree
, n_instances :: Int
, n_derivations :: Int
, n_syntax_constructs :: Int
, n_abc_instructions :: Int
}
/**
......@@ -69,13 +72,14 @@ instance < AnnotationKey
* Wrapper around different kinds of entries to store all in one database.
*/
:: CloogleEntry
= FunctionEntry FunctionEntry
| TypeDefEntry TypeDefEntry
| ModuleEntry ModuleEntry
| ClassEntry ClassEntry
| InstanceEntry InstanceEntry
| DeriveEntry DeriveEntry
| SyntaxEntry SyntaxEntry
= FunctionEntry FunctionEntry
| TypeDefEntry TypeDefEntry
| ModuleEntry ModuleEntry
| ClassEntry ClassEntry
| InstanceEntry InstanceEntry
| DeriveEntry DeriveEntry
| SyntaxEntry SyntaxEntry
| ABCInstructionEntry ABCInstructionEntry
derive JSONEncode CloogleEntry
derive JSONDecode CloogleEntry
......@@ -183,6 +187,17 @@ location :: !Library !String !FilePath !LineNr !LineNr !Name -> Location
, syntax_examples :: [SyntaxExample] //* Some code examples (should include comments)
}
/**
* Information about an ABC instruction.
* This is very similar to {{`ABCInstructionResultExtras`}}, but also includes
* a description string.
*/
:: ABCInstructionEntry =
{ aie_instruction :: String //* The name of the instruction
, aie_arguments :: [ABCArgument] //* The arguments
, aie_description :: String //* A description for documentation
}
/**
* A search pattern for syntax constructs
*/
......
......@@ -62,12 +62,12 @@ derive JSONEncode ClassDoc, ClassEntry, ClassMemberDoc, CloogleEntry,
Constructor, ConstructorDoc, DeriveEntry, FunctionDoc, FunctionEntry,
InstanceEntry, Location, ModuleDoc, ModuleEntry, Priority, RecordField,
SyntaxEntry, Type, TypeDef, TypeDefEntry, TypeDefRhs, TypeDoc,
TypeRestriction
TypeRestriction, ABCInstructionEntry
derive JSONDecode ClassDoc, ClassEntry, ClassMemberDoc, CloogleEntry,
Constructor, ConstructorDoc, DeriveEntry, FunctionDoc, FunctionEntry,
InstanceEntry, Location, ModuleDoc, ModuleEntry, Priority, RecordField,
SyntaxEntry, Type, TypeDef, TypeDefEntry, TypeDefRhs, TypeDoc,
TypeRestriction
TypeRestriction, ABCInstructionEntry
printersperse :: Bool a [b] -> [String] | print a & print b
printersperse ia a bs = intercalate (print False a) (map (print ia) bs)
......@@ -238,7 +238,7 @@ classContext ce = ce.ce_context
saveDB :: !*CloogleDB !*File -> *(!*CloogleDB, !*File)
saveDB wrapper=:{db,name_ngrams,name_map,types,core,apps,builtins,syntax,
library_map,module_map,derive_map,instance_map,always_unique} f
abc_instrs,library_map,module_map,derive_map,instance_map,always_unique} f
# (db,f) = 'DB'.saveDB db f
# f = write name_ngrams f
# f = write name_map f
......@@ -247,6 +247,7 @@ saveDB wrapper=:{db,name_ngrams,name_map,types,core,apps,builtins,syntax,
# f = write apps f
# f = write builtins f
# f = write syntax f
# f = write abc_instrs f
# f = write library_map f
# f = write module_map f
# f = write derive_map f
......@@ -268,6 +269,7 @@ openDB f
# (apps,f) = read f
# (builtins,f) = read f
# (syntax,f) = read f
# (abc_instrs,f) = read f
# (library_map,f) = read f
# (module_map,f) = read f
# (derive_map,f) = read f
......@@ -281,6 +283,7 @@ openDB f
apps >>= \apps ->
builtins >>= \builtins ->
syntax >>= \syntax ->
abc_instrs >>= \abc_instrs ->
library_map >>= \library_map ->
module_map >>= \module_map ->
derive_map >>= \derive_map ->
......@@ -294,6 +297,7 @@ openDB f
, apps=apps
, builtins=builtins
, syntax=syntax
, abc_instrs=abc_instrs
, library_map=library_map
, module_map=module_map
, derive_map=derive_map
......@@ -321,13 +325,14 @@ dbStats wrap=:{db,types}
= (stats, {wrap & db=db})
where
count :: CloogleEntry CloogleDBStats -> CloogleDBStats
count (ModuleEntry _) st = {st & n_modules=st.n_modules+1}
count (FunctionEntry _) st = {st & n_functions=st.n_functions+1}
count (ClassEntry _) st = {st & n_classes=st.n_classes+1}
count (TypeDefEntry _) st = {st & n_type_definitions=st.n_type_definitions+1}
count (InstanceEntry _) st = {st & n_instances=st.n_instances+1}
count (DeriveEntry _) st = {st & n_derivations=st.n_derivations+1}
count (SyntaxEntry _) st = {st & n_syntax_constructs=st.n_syntax_constructs+1}
count (ModuleEntry _) st = {st & n_modules=st.n_modules+1}
count (FunctionEntry _) st = {st & n_functions=st.n_functions+1}
count (ClassEntry _) st = {st & n_classes=st.n_classes+1}
count (TypeDefEntry _) st = {st & n_type_definitions=st.n_type_definitions+1}
count (InstanceEntry _) st = {st & n_instances=st.n_instances+1}
count (DeriveEntry _) st = {st & n_derivations=st.n_derivations+1}
count (SyntaxEntry _) st = {st & n_syntax_constructs=st.n_syntax_constructs+1}
count (ABCInstructionEntry _) st = {st & n_abc_instructions=st.n_abc_instructions+1}
zero :: CloogleDBStats
zero =
......@@ -341,6 +346,7 @@ where
, n_instances = 0
, n_derivations = 0
, n_syntax_constructs = 0
, n_abc_instructions = 0
}
writeTypeTree :: !*CloogleDB !*File -> *(*CloogleDB, *File)
......@@ -396,9 +402,10 @@ where
idxs = foldr merge [] $ catMaybes $ map (flip get module_map) ss
filterName :: !String !*CloogleDB -> *CloogleDB
filterName s wrap=:{db,name_ngrams,syntax}
filterName s wrap=:{db,name_ngrams,syntax,abc_instrs}
# db = 'DB'.searchIndices Intersect indices db
# db = 'DB'.searchWithIndices syntaxSearch syntax db
# db = 'DB'.searchWithIndices abcSearch abc_instrs db
= {wrap & db=db}
where
indices = [(i,[(MatchingNGrams,n)]) \\ (i,n) <- 'NGrams'.search s name_ngrams]
......@@ -407,6 +414,10 @@ where
syntaxSearch (SyntaxEntry se) = (any (flip patternMatches s) se.syntax_patterns, [])
syntaxSearch _ = (False, [])
abcSearch :: CloogleEntry -> (Bool, [a])
abcSearch (ABCInstructionEntry ie) = (ie.aie_instruction == s, [])
abcSearch _ = (False, [])
patternMatches :: SyntaxPattern String -> Bool
patternMatches p s = m [c \\ c <-: p] [c \\ c <-: s]
where
......
......@@ -81,9 +81,10 @@ from CloogleDB import
:: TypeDefEntry{tde_loc,tde_instances,tde_derivations,tde_usages},
:: ClassEntry{ce_loc,ce_instances,ce_is_meta,ce_members,ce_usages},
classContext, :: TypeRestriction,
:: SyntaxEntry, :: DeriveEntry,
:: SyntaxEntry,
:: InstanceEntry{ie_class,ie_types,ie_locations},
:: DeriveEntry{..},
:: ABCInstructionEntry{..}, :: ABCArgument,
instance zero FunctionEntry, instance zero ModuleEntry,
class getLocation, instance getLocation CloogleEntry,
instance == Location,
......@@ -174,6 +175,7 @@ finaliseDB extra tdb =
, apps = appidxs
, builtins = idxfilter \e -> fromMaybe False ('CDB'.isBuiltin <$> 'CDB'.getLocation e)
, syntax = idxfilter \e -> e=:(SyntaxEntry _)
, abc_instrs = idxfilter \e -> e=:(ABCInstructionEntry _)
, library_map = libmap
, module_map = modmap
, derive_map = 'M'.fromList
......
......@@ -63,7 +63,7 @@ search {unify,name,className,typeName,using,modules,libraries,page,include_built
Just ms -> filterModules ms cdb
Nothing -> cdb
# cdb = if include_builtins includeBuiltins excludeBuiltins cdb
// Search strategie
// Search strategy
# strat = SSIdentity
// Name search
# strat = addStrategy (SSName <$> name) strat
......@@ -255,14 +255,24 @@ makeResult orgsearchtype allsyns usedsyns (entry, annots) db
# (SyntaxEntry se) = entry
= (Just $ SyntaxResult (
{ general
& distance = -1000
, documentation = Just se.syntax_description
& documentation = Just se.syntax_description
},
{ SyntaxResultExtras
| syntax_title = se.SyntaxEntry.syntax_title
, syntax_code = se.SyntaxEntry.syntax_code
, syntax_examples = se.SyntaxEntry.syntax_examples
}), db)
| entry =: (ABCInstructionEntry _)
# (ABCInstructionEntry aie) = entry
= (Just $ ABCInstructionResult (
{ general
& documentation = Just aie.aie_description
},
{ abc_instruction = aie.aie_instruction
, abc_arguments = aie.aie_arguments
}), db)
| otherwise // InstanceEntry / DeriveEntry cannot be returned
= (Nothing, db)
where
......
Subproject commit 1a13b24887c4289f33b4c9d644aa99ee3bad337a
Subproject commit e7d89bffdb4d3403ffe4043f021cc7b7452f91ed
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment