diff --git a/docs/development/including_modules.md b/docs/development/including_modules.md new file mode 100644 index 0000000..f201a0b --- /dev/null +++ b/docs/development/including_modules.md @@ -0,0 +1,60 @@ +# Modules inclusion + +Module is, at the low level, a statement that modifies a given context by adding +here local and exported symbols, performing some tasks and even returning some value +we don't need for now. + +The compiled module is therefore a statement. When we execute it on some context, +it wills it with all it symbols, private too. + +If we call it on another context, it will do it once more, no caching. This is unnecessary +if not dangerous repetition. + +## What is inclusion? + +The _goal_ of the inclusion is to make _exported symbols_ available in a given context, +without re-executing included module initialization code. So, when we hit the `import foo`, +we should check that foo module was executed, execute it if not on special context we store in the library, then copy all public symbols from fooContext into current one. + +## Class pseudo-module + +Mostly same we can do with a class + +## Module initialization + +We can just put the code into the module code: + + module lying.samples.module + // or package? + + val startuptTime = Instant.now() + + // private: not available from outside + private fun moduleInitialization() { + // long code + } + + // this will be called only once + moduleInitialization() + +## class initialization + + class foo { + + private static var instanceCounter = 0 + + val instanceId = instanceCounter + + fun close() { + instanceCounter-- + } + + // instance initializatino could be as this: + if( instanceId > 100 ) + throw Exception("Too many instances") + + static { + // static, one-per-class initializer could be posted here + instanceCounter = 1 + } + } diff --git a/library/src/commonMain/kotlin/net/sergeych/lyng/SymbolSpace.kt b/library/src/commonMain/kotlin/net/sergeych/lyng/SymbolSpace.kt new file mode 100644 index 0000000..9ff22f6 --- /dev/null +++ b/library/src/commonMain/kotlin/net/sergeych/lyng/SymbolSpace.kt @@ -0,0 +1,13 @@ +package net.sergeych.lyng + + + +class Symbols( + unitType: UnitType, + val name: String, + val x: TypeDecl +) { + enum class UnitType { + Module, Function, Lambda + } +} \ No newline at end of file diff --git a/library/src/commonMain/kotlin/net/sergeych/lyng/TypeDecl.kt b/library/src/commonMain/kotlin/net/sergeych/lyng/TypeDecl.kt index 35c890b..8fbed99 100644 --- a/library/src/commonMain/kotlin/net/sergeych/lyng/TypeDecl.kt +++ b/library/src/commonMain/kotlin/net/sergeych/lyng/TypeDecl.kt @@ -1,5 +1,21 @@ package net.sergeych.lyng sealed class TypeDecl { + // ?? + data class Fn(val argTypes: List, val retType: TypeDecl) : TypeDecl() object Obj : TypeDecl() -} \ No newline at end of file +} + +/* +To use in the compiler, we need symbol information when: + +- declaring a class: the only way to export its public/protected symbols is to know it in compiler time +- importing a module: actually, we cam try to do it in a more efficient way. + +Importing module: + +The moudule is efficiently a statement, that initializes it with all its symbols modifying some context. + +The thing is, we need only + + */ \ No newline at end of file