about summary refs log tree commit diff stats
path: root/apps/tile/data.mu
blob: c9988ed3ad4700252bc25a6ffb5b19ac7b29fa16 (plain) (blame)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
type program {
  defs: (handle function)
  sandboxes: (handle sandbox)
}

type sandbox {
  setup: (handle line)
  data: (handle line)
  next: (handle sandbox)
  prev: (handle sandbox)
}

type function {
  args: (handle word)
  body: (handle line)
  # some sort of indication of spatial location
  next: (handle function)
}

type line {
  name: (handle array byte)
  data: (handle word)
  result: (handle result)  # might be cached
  next: (handle line)
  prev: (handle line)
}

#? type word {
#?   # at most one of these will be non-null
#?   scalar-data: (handle gap-buffer)
#?   box-data: (handle line)  # recurse
#?   left: (handle word)
#?   right: (handle word)
#? }

type result {
  data: (handle word-stack)
  error: (handle array byte)  # single error message for now
}

# if 'out' is non-null, save the first word of the program there
fn initialize-program _program: (addr program), out: (addr handle word) {
  var program/esi: (addr program) <- copy _program
  var sandbox-ah/eax: (addr handle sandbox) <- get program, sandboxes
  allocate sandbox-ah
  var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah
  initialize-sandbox sandbox, out
}

# if 'out' is non-null, save the first word of the sandbox there
fn initialize-sandbox _sandbox: (addr sandbox), out: (addr handle word) {
  var sandbox/esi: (addr sandbox) <- copy _sandbox
  var line-ah/eax: (addr handle line) <- get sandbox, data
  allocate line-ah
  var line/eax: (addr line) <- lookup *line-ah
  initialize-line line, out
}

# initialize line with a single empty word
# if 'out' is non-null, save the word there as well
fn initialize-line _line: (addr line), out: (addr handle word) {
  var line/esi: (addr line) <- copy _line
  var word-ah/eax: (addr handle word) <- get line, data
  allocate word-ah
  {
    compare out, 0
    break-if-=
    var dest/edi: (addr handle word) <- copy out
    copy-object word-ah, dest
  }
  var word/eax: (addr word) <- lookup *word-ah
  initialize-word word
}