Skip to content

Commit afb0463

Browse files
committed
Added const attributes.
1 parent 873aced commit afb0463

6 files changed

Lines changed: 224 additions & 68 deletions

File tree

makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ test: debug
435435
@./$(BIN_NAME) $(TEST_INPUT)/loops.yue -o $(TEST_OUTPUT)/5.1/loops.lua --target=5.1
436436
@./$(BIN_NAME) $(TEST_INPUT)/try_catch.yue -o $(TEST_OUTPUT)/5.1/try_catch.lua --target=5.1
437437
@./$(BIN_NAME) $(TEST_INPUT)/attrib.yue -o $(TEST_OUTPUT)/5.1/attrib.lua --target=5.1
438+
@./$(BIN_NAME) $(TEST_INPUT)/import_global.yue -o $(TEST_OUTPUT)/5.1/import_global.lua --target=5.1
438439
@./$(BIN_NAME) $(TEST_INPUT)/test/loops_spec.yue -o $(TEST_OUTPUT)/5.1/test/loops_spec.lua --target=5.1
439440
@./$(BIN_NAME) -e spec/inputs/compile_doc.yue $(TEST_OUTPUT)
440441
@echo -en "Compile time: "
@@ -454,6 +455,7 @@ gen: release
454455
@./$(BIN_NAME) $(TEST_INPUT)/loops.yue -o $(GEN_OUTPUT)/5.1/loops.lua --target=5.1
455456
@./$(BIN_NAME) $(TEST_INPUT)/try_catch.yue -o $(GEN_OUTPUT)/5.1/try_catch.lua --target=5.1
456457
@./$(BIN_NAME) $(TEST_INPUT)/attrib.yue -o $(GEN_OUTPUT)/5.1/attrib.lua --target=5.1
458+
@./$(BIN_NAME) $(TEST_INPUT)/import_global.yue -o $(GEN_OUTPUT)/5.1/import_global.lua --target=5.1
457459
@./$(BIN_NAME) $(TEST_INPUT)/test/loops_spec.yue -o $(GEN_OUTPUT)/5.1/test/loops_spec.lua --target=5.1
458460
@./$(BIN_NAME) -e spec/inputs/compile_doc.yue $(GEN_OUTPUT)
459461
@echo -en "Compile time: "

spec/outputs/5.1/import_global.lua

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
do
2+
local print = print
3+
local math = math
4+
print("hello")
5+
math.random(10)
6+
end
7+
do
8+
local print = print
9+
local value = 1
10+
value = value + 2
11+
print(value)
12+
end
13+
do
14+
local print
15+
print = function(msg)
16+
return msg
17+
end
18+
do
19+
local math = math
20+
print("local")
21+
math.random(1)
22+
end
23+
end
24+
do
25+
local print = print
26+
local tostring
27+
tostring = function(v)
28+
return "local"
29+
end
30+
tostring("value")
31+
print(tostring(123))
32+
end
33+
do
34+
local func
35+
func = function(x, y)
36+
local type = type
37+
local tostring = tostring
38+
local print = print
39+
return type(x, tostring(y, print))
40+
end
41+
func(1, 2)
42+
end
43+
do
44+
local xpcall = xpcall
45+
local func = func
46+
local world = world
47+
local tostring = tostring
48+
local print = print
49+
xpcall(function()
50+
return func("hello " .. tostring(world))
51+
end, function(err)
52+
return print(err)
53+
end)
54+
end
55+
do
56+
local print = print
57+
print(FLAG)
58+
FLAG = 123
59+
end
60+
do
61+
local print = print
62+
Foo = 10
63+
print(Foo)
64+
Foo = Foo + 2
65+
end
66+
do
67+
local print = print
68+
Bar = 1
69+
Baz = 2
70+
print(Bar, Baz)
71+
end
72+
do
73+
local y = y
74+
x = 3434
75+
if y then
76+
x = 10
77+
end
78+
end
79+
do
80+
local lowercase = lowercase
81+
local tostring = tostring
82+
local Uppercase = Uppercase
83+
local foobar = "all " .. tostring(lowercase)
84+
FooBar = "pascal case"
85+
FOOBAR = "all " .. tostring(Uppercase)
86+
end
87+
do
88+
local setmetatable = setmetatable
89+
local print = print
90+
do
91+
local _class_0
92+
local _base_0 = { }
93+
if _base_0.__index == nil then
94+
_base_0.__index = _base_0
95+
end
96+
_class_0 = setmetatable({
97+
__init = function() end,
98+
__base = _base_0,
99+
__name = "A"
100+
}, {
101+
__index = _base_0,
102+
__call = function(cls, ...)
103+
local _self_0 = setmetatable({ }, _base_0)
104+
cls.__init(_self_0, ...)
105+
return _self_0
106+
end
107+
})
108+
_base_0.__class = _class_0
109+
A = _class_0
110+
end
111+
Flag = 1
112+
const, x, y = "const", 1, 2
113+
print(math, table)
114+
end
115+
do
116+
local X = X
117+
X:func(1, 2, 3)
118+
X.tag = "abc"
119+
return X
120+
end

spec/outputs/codes_from_doc.lua

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,6 @@ local tb = {
408408
}
409409
}
410410
}
411-
do
412-
local print = print
413-
local math = math
414-
print("hello")
415-
math.random(3)
416-
end
417-
do
418-
local print = print
419-
print(FLAG)
420-
FLAG = 123
421-
end
422411
do
423412
local insert, concat = table.insert, table.concat
424413
local C, Ct, Cmt
@@ -452,6 +441,25 @@ do
452441
local _obj_0 = require("export")
453442
one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
454443
end
444+
do
445+
local tostring <const> = tostring
446+
local concat <const> = table.concat
447+
print(concat({
448+
"a",
449+
tostring(1)
450+
}))
451+
end
452+
do
453+
local print <const> = print
454+
local math <const> = math
455+
print("hello")
456+
math.random(3)
457+
end
458+
do
459+
local print <const> = print
460+
print(FLAG)
461+
FLAG = 123
462+
end
455463
local _module_0 = { }
456464
local a, b, c = 1, 2, 3
457465
_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
@@ -2927,17 +2935,6 @@ local tb = {
29272935
}
29282936
}
29292937
}
2930-
do
2931-
local print = print
2932-
local math = math
2933-
print("hello")
2934-
math.random(3)
2935-
end
2936-
do
2937-
local print = print
2938-
print(FLAG)
2939-
FLAG = 123
2940-
end
29412938
do
29422939
local insert, concat = table.insert, table.concat
29432940
local C, Ct, Cmt
@@ -2971,6 +2968,25 @@ do
29712968
local _obj_0 = require("export")
29722969
one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
29732970
end
2971+
do
2972+
local tostring <const> = tostring
2973+
local concat <const> = table.concat
2974+
print(concat({
2975+
"a",
2976+
tostring(1)
2977+
}))
2978+
end
2979+
do
2980+
local print <const> = print
2981+
local math <const> = math
2982+
print("hello")
2983+
math.random(3)
2984+
end
2985+
do
2986+
local print <const> = print
2987+
print(FLAG)
2988+
FLAG = 123
2989+
end
29742990
local _module_0 = { }
29752991
local a, b, c = 1, 2, 3
29762992
_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c

spec/outputs/codes_from_doc_zh.lua

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,6 @@ local tb = {
408408
}
409409
}
410410
}
411-
do
412-
local print = print
413-
local math = math
414-
print("hello")
415-
math.random(3)
416-
end
417-
do
418-
local print = print
419-
print(FLAG)
420-
FLAG = 123
421-
end
422411
do
423412
local insert, concat = table.insert, table.concat
424413
local C, Ct, Cmt
@@ -452,6 +441,25 @@ do
452441
local _obj_0 = require("export")
453442
one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
454443
end
444+
do
445+
local tostring <const> = tostring
446+
local concat <const> = table.concat
447+
print(concat({
448+
"a",
449+
tostring(1)
450+
}))
451+
end
452+
do
453+
local print <const> = print
454+
local math <const> = math
455+
print("hello")
456+
math.random(3)
457+
end
458+
do
459+
local print <const> = print
460+
print(FLAG)
461+
FLAG = 123
462+
end
455463
local _module_0 = { }
456464
local a, b, c = 1, 2, 3
457465
_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c
@@ -2921,17 +2929,6 @@ local tb = {
29212929
}
29222930
}
29232931
}
2924-
do
2925-
local print = print
2926-
local math = math
2927-
print("hello")
2928-
math.random(3)
2929-
end
2930-
do
2931-
local print = print
2932-
print(FLAG)
2933-
FLAG = 123
2934-
end
29352932
do
29362933
local insert, concat = table.insert, table.concat
29372934
local C, Ct, Cmt
@@ -2965,6 +2962,25 @@ do
29652962
local _obj_0 = require("export")
29662963
one, two, ch = _obj_0[1], _obj_0[2], _obj_0.Something.umm[1]
29672964
end
2965+
do
2966+
local tostring <const> = tostring
2967+
local concat <const> = table.concat
2968+
print(concat({
2969+
"a",
2970+
tostring(1)
2971+
}))
2972+
end
2973+
do
2974+
local print <const> = print
2975+
local math <const> = math
2976+
print("hello")
2977+
math.random(3)
2978+
end
2979+
do
2980+
local print <const> = print
2981+
print(FLAG)
2982+
FLAG = 123
2983+
end
29682984
local _module_0 = { }
29692985
local a, b, c = 1, 2, 3
29702986
_module_0["a"], _module_0["b"], _module_0["c"] = a, b, c

0 commit comments

Comments
 (0)