-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock.m
79 lines (71 loc) · 2.51 KB
/
block.m
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
74
75
76
77
78
79
export Block
const block <- class Block (Tree) [xxstats : Tree, xxunavailablehandler : Tree, xxfailurehandler : Tree]
field stats : Tree <- xxstats
field unavailablehandler : Tree <- xxunavailablehandler
field failurehandler : Tree <- xxfailurehandler
field st : SymbolTable
export function upperbound -> [r : Integer]
r <- 2
end upperbound
export function getElement [i : Integer] -> [r : Tree]
if i = 0 then
r <- stats
elseif i = 1 then
r <- unavailablehandler
elseif i = 2 then
r <- failurehandler
end if
end getElement
export operation setElement [i : Integer, r : Tree]
if i = 0 then
stats <- r
elseif i = 1 then
unavailablehandler <- r
elseif i = 2 then
failurehandler <- r
end if
end setElement
export operation copy [i : Integer] -> [r : Tree]
var nstats, nunavailablehandler, nfailurehandler : Tree
if stats !== nil then nstats <- stats.copy[i] end if
if unavailablehandler !== nil then
nunavailablehandler <- unavailablehandler.copy[i] end if
if failurehandler !== nil then
nfailurehandler <- failurehandler.copy[i] end if
r <- block.create[ln, nstats, nunavailablehandler, nfailurehandler]
end copy
export operation defineSymbols[pst : SymbolTable]
self$st <- SymbolTable.create[pst, CBlock]
self$st$myTree <- self
FTree.defineSymbols[self$st, self]
end defineSymbols
export operation resolveSymbols [pst : SymbolTable, nexp : Integer]
FTree.resolveSymbols[self$st, self, 0]
end resolveSymbols
export operation generate [xct : Printable]
const ct <- view xct as ByteCode
var fh : HandlerRecord
var uh : HandlerRecord
const label : Integer <- ct.fetchnest
if false and label !== nil and (failurehandler !== nil or unavailablehandler !== nil)then
Environment.getEnv.SemanticError[ln, "Failure/Unavailable handers in loops are not supported", nil]
end if
if failurehandler !== nil then
fh <- ct.beginHandlerBlock[failurehandler]
end if
if unavailablehandler !== nil then
uh <- ct.beginHandlerBlock[unavailablehandler]
uh$name <- 1
if unavailablehandler[0] !== nil then
const thesym : Symbol <- (view unavailablehandler[0][0] as Sym)$mysym
uh$varOffset <- thesym$offset
end if
end if
stats.generate[xct]
if uh !== nil then ct.endHandlerBlock end if
if fh !== nil then ct.endHandlerBlock end if
end generate
export function asString -> [r : String]
r <- "block"
end asString
end Block