Imports
The locations that an import names, sources as values of std:Import.Source, requests with headers and TLS settings, integrity hashes and freezing.
An import is an expression that stands for the value of another source. A source is usually written as a location:
./helper.omg a file, relative to the source of the import
../lib/helper.omg
/etc/omegyu/config.omg an absolute path
~/config.omg a path relative to the home directory
std:List a module of the standard library
env:CONFIG an environment variable that holds an expression
https://example.com/x.omg a URL, also with httpstd:List.map selects a field of a module directly. A field of a file or
of a URL needs parentheses, (./helper.omg).field, because dots belong
to paths. A module of the standard library in a directory is named by its
path, with slashes, as in std:EVM/State/Layout/Address.width. Each source
is loaded and checked once, and imports may not form a cycle.
Sources as values
import s imports the source s, a value of type std:Import.Source:
std:Import.SourceNormal form
< Env : Text
| File : Text
| Http :
{ body : Optional Text
, headers :
List
{ name : Text
, prefix : Text
, value : < Env : Text | File : Text | Text : Text >
}
, method : Text
, tls :
{ ca : Optional Text
, certificate : Optional Text
, insecure : Bool
, key : Optional < Env : Text | File : Text | Text : Text >
}
, url : Text
}
| Std : Text
>A location is short for such a value: ./x.omg is
import (std:Import.Source.File "./x.omg"), and a URL is
import (std:Import.get "https://…"). A request says more than its URL:
its method, its headers, its body and its TLS settings, which are a CA
bundle trusted instead of the system's, a client certificate and key for
mutual TLS, or insecure = True. The value of a header, and the client's
key, is a Secret: written out, or read from an environment variable or a
file when the request is sent. A secret is never part of a hash or of the
cache.
std:Import.http
(((std:Import.request
"GET"
"https://example.com/config.omg") with headers =
[ std:Import.bearer (std:Import.Secret.Env "TOKEN")
]) with tls.ca =
Some "/etc/ssl/internal-ca.pem")Type
std:Import.SourceThe expression after import is evaluated before the file that contains
it is checked, because every import is resolved first. It can use builtins
and imports, but not the definitions of the file:
let path = "./helper.omg"
in import (std:Import.Source.File path)Error E0208
error[E0208]: the source of an import cannot use `path`
┌─ example.omg:2:36
│
2 │ in import (std:Import.Source.File path)
│ ^^^^ this is not a builtin, nor an import
│
= the source of an import is evaluated before the file that contains it is checked: it can use builtins and imports, and none of the definitions of the file
import takes one argument, as an application does: put a larger
expression between parentheses.
A relative path in a remote source is relative to its URL, and is fetched with the same headers and TLS settings. A remote source can import other URLs and the standard library, but not a local file or an environment variable.
Hashes
An import can be followed by the hash of the module that it checks to, as
in ./helper.omg sha256:3f…. The import fails with E0209 when its module
has another hash. With the hash, the module is read from the cache without
its source being read, even when the source is gone or the server is down.
The hash identifies the checked module: comments, layout and the names of
variables do not change it, but a new version of omegyu may.
omegyu freeze FILE… writes the hash after each import of the files, except
those of the standard library, and updates the hashes that changed. It
leaves the rest of the text as it is. omegyu freeze --check FILE… changes
nothing, and fails when an import is not pinned to the hash of what it
checks to.
The cache
The modules that a program imports are cached once they are checked, and a module whose source and imports have not changed is read back instead of being checked again. Imports and the cache describes what the cache holds and what it assumes.