-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects.lua
110 lines (106 loc) · 2.64 KB
/
objects.lua
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
-- This defines all the default types implementations
toast.objects = {
["cell"] = {
["init"] = function(ctx, meta, templ)
meta.static_size = 1
return {"code",
{"seek", meta[1]},
{"bf", "[-]"},
}
end,
["movemulti"] = function(ctx, meta, meta2s)
local code = {"code"}
for k,v in pairs(meta2s) do
table.insert(code, {"seek", v[1]})
table.insert(code, {"bf", "[-]"})
end
table.insert(code, {"seek", meta[1]})
table.insert(code, {"bf", "[-"})
for k,v in pairs(meta2s) do
table.insert(code, {"seek", v[1]})
table.insert(code, {"bf", "+"})
end
table.insert(code, {"seek", meta[1]})
table.insert(code, {"bf", "]"})
return code
end,
["move"] = function(ctx, meta, meta2)
return toast.objects.int.movemulti(meta,{meta2})
end,
["copymulti"] = function(ctx, meta, meta2s)
local tmp1 = ctx.newTemp()
return {"code",
{"push", "int", tmp1},
toast.objects.int.move(ctx, meta, {tmp1,}),
toast.objects.int.movemulti(ctx, {tmp1}, meta2s),
}
end,
["copy"] = function(ctx, meta, meta2)
return toast.objects.int.copymulti(meta, {meta2s})
end,
},
["int"] = {
["init"] = function(ctx, meta, templ)
meta.static_size = 1 -- when bigger ints are supported this will be set higher
return {"code",
{"seek", meta[1]},
{"bf", "[-]>[-]>[-]>[-]<<<"},
{"seeked", "right"},
}
end,
["move"] = function(ctx, meta, meta2)
return toast.objects.int.movemulti(meta,{meta2})
end,
["copymulti"] = function(ctx, meta, meta2s)
local tmp1 = ctx.newTemp()
return {"code",
{"push", "int", tmp1},
toast.objects.int.move(ctx, meta, {tmp1,}),
toast.objects.int.movemulti(ctx, {tmp1}, meta2s),
}
end,
["copy"] = function(ctx, meta, meta2)
return toast.objects.int.copymulti(meta, {meta2s})
end,
},
-- simple string, text is surrounded in 0s so it can be seeked over
["string"] = {
["init"] = function(ctx, meta, templ)
meta.dynamic = true
return {"code",
{"seek", name},
{"bf", "[-]>[-]<"}
}
end,
["seekleft"] = function(meta)
return "<[<]"
end,
["seekright"] = function(meta)
return ">[>]>"
end,
},
-- internal structure
-- 0 item[index, data, temp0, temp1] ... 0
["array"] = {
["init"] = function(ctx, meta, templ)
meta.dynamic = true
return {"code",
{"bf", "[-]>[-]<"}
}
end,
["seekleft"] = function(ctx,meta)
return "<<[<<<]"
end,
["seekright"] = function(ctx,meta)
return ">[>>>]>"
end,
["index"] = function(ctx, meta, meta2, meta3) -- this, index, output
return {"code", clobbers = {meta2},
{"seek", meta[2]},
}
end,
["newindex"] = function(ctx, meta, meta2)
-- TODO
end,
}
}