-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewexp.m
78 lines (68 loc) · 1.79 KB
/
newexp.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
export newexp
const newexp <- class Newexp (Tree) [xxexp : Tree, xxargs : Tree]
field exp : Tree <- xxexp
field args : Tree <- xxargs
export function upperbound -> [r : Integer]
r <- 1
end upperbound
export function getElement [i : Integer] -> [r : Tree]
if i = 0 then
r <- exp
elseif i = 1 then
r <- args
end if
end getElement
export operation setElement [i : Integer, r : Tree]
if i = 0 then
exp <- r
elseif i = 1 then
args <- r
end if
end setElement
export operation copy [i : Integer] -> [r : Tree]
var nexp, nargs : Tree
if exp !== nil then nexp <- exp.copy[i] end if
if args !== nil then nargs <- args.copy[i] end if
r <- newexp.create[ln, nexp, nargs]
end copy
export operation getAT -> [r : Tree]
const ct : Tree <- exp.execute
if ct !== nil then
r <- (view ct as hasInstAT)$instAT
end if
end getAT
export operation getCT -> [r : Tree]
const ct : Tree <- exp.execute
if ct !== nil then
r <- (view ct as hasInstCT)$instCT
end if
end getCT
export operation generate[xct : Printable]
const bc <- view xct as ByteCode
% The order of stuff on the stack for a creation is:
% NIL
% arguments for the initially - 8 bytes each
% Concrete type
bc.addCode["PUSHNIL"]
if self$args !== nil then
bc.pushSize[8]
self$args.generate[xct]
bc.popSize
end if
bc.pushSize[4]
self$exp.generate[bc]
bc.popSize
% if self$isVector then
% bc.addCode["LDAS"]
% bc.addValue[0, 2]
% bc.addCode["CREATEVEC"]
% else
% bc.addCode["CREATE"]
% end if
bc.addCode["CREATE"]
if bc$size != 4 then bc.addCode["PUSHCT"] end if
end generate
export function asString -> [r : String]
r <- "newexp"
end asString
end Newexp