aboutsummaryrefslogtreecommitdiff
path: root/lib/secrets.nom
blob: 4dd5a7a2eb3a9a78c7d37c928fc7780e515c60c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "lib/core.nom"

macro block [with secrets %block] =: ".."
    |local secrets = {}
    |\(%block's "value") as lua block\

macro block [with secrets as %secret_name %block] =: ".."
    |local \%secret_name as value\ = {}
    |\(%block's "value") as lua block\

# Access the lua variable that should be within scope
macro [secrets] =: "secrets"

macro [secret %key, secret value of %key, secret value for %key] =:
    if ((%key's "type") != "Var"):
        error ".."
            |Wrong type, expected Var, but got: \%key's "type"\
    ".."|secrets[\repr (%key's "value")\]

macro block [secret %key = %new_value] =:
    lua block ".."
        |if vars.key.type ~= "Var" then
        |    compiler:error("Assignment operation has the wrong type for the left hand side. "
        |        .."Expected Var, but got: "..vars.key.type)
        |end
        |if vars.new_value.type ~= "Thunk" then
        |    compiler:error("Assignment operation has the wrong type for the right hand side. "
        |        .."Expected Thunk, but got: "..vars.new_value.type.."\\nMaybe you used '=' instead of '=:'?")
        |end
    ".."|do
        |    local ret
        |    \lua expr "compiler:tree_to_lua(vars.new_value.value, 'Statement')"\
        |    secrets[\repr (%key's "value")\] = ret
        |end