Skip to content

Commit bfe2062

Browse files
committed
update: successfully transpile and run ccomplete#Complete
1 parent 0277abc commit bfe2062

7 files changed

Lines changed: 47 additions & 23 deletions

File tree

crates/vim9-gen/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,11 +1025,12 @@ impl Generate for Register {
10251025

10261026
impl Generate for PrefixExpression {
10271027
fn gen(&self, state: &mut State) -> String {
1028-
format!(
1029-
"NVIM9.prefix['{:?}']({})",
1030-
self.operator,
1031-
self.right.gen(state)
1032-
)
1028+
let right = self.right.gen(state);
1029+
match &self.operator {
1030+
parser::Operator::Increment => format!("{right} = {right} + 1"),
1031+
parser::Operator::Decrement => format!("{right} = {right} - 1"),
1032+
_ => format!("NVIM9.prefix['{:?}']({right})", self.operator,),
1033+
}
10331034
}
10341035
}
10351036

crates/vim9-gen/testdata/busted/assign.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,13 @@ def Test_unpacked_identifiers()
5353
assert_equal(1, x)
5454
assert_equal(2, y)
5555
enddef
56+
57+
def Test_modifier_prefixes()
58+
var foo = 10
59+
--foo
60+
assert_equal(9, foo)
61+
62+
++foo
63+
++foo
64+
assert_equal(11, foo)
65+
enddef

crates/vim9-gen/testdata/busted/methods_2.vim

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
var foo = [1, 2, 3]
2-
foo
3-
# Remove members, these can't appear without something in front.
4-
->filter((_, y): bool =>
5-
y == 2)
6-
71
def Test_method_comments()
82
var x = [1, 2, 3]
93
x

crates/vim9-gen/testdata/output/busted_assign.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local __VIM9_MODULE = {}
33
describe("filename", function()
44
local Test_assignment_bool = nil
55
local Test_unpacked_identifiers = nil
6+
local Test_modifier_prefixes = nil
67
-- vim9script
78

89
it("Test_assignment_bool", function()
@@ -72,5 +73,22 @@ describe("filename", function()
7273
-- Assert that errors is still empty
7374
assert.are.same({}, vim.v.errors)
7475
end)
76+
77+
it("Test_modifier_prefixes", function()
78+
-- Set errors to empty
79+
vim.v.errors = {}
80+
81+
-- Actual test
82+
local foo = 10
83+
foo = foo - 1
84+
NVIM9.fn["assert_equal"](9, foo)
85+
86+
foo = foo + 1
87+
foo = foo + 1
88+
NVIM9.fn["assert_equal"](11, foo)
89+
90+
-- Assert that errors is still empty
91+
assert.are.same({}, vim.v.errors)
92+
end)
7593
end)
7694
return __VIM9_MODULE

crates/vim9-gen/testdata/output/busted_methods_2.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ local NVIM9 = require("vim9script")
22
local __VIM9_MODULE = {}
33
describe("filename", function()
44
local Test_method_comments = nil
5-
local foo = { 1, 2, 3 }
6-
NVIM9.fn_mut("filter", {
7-
foo,
8-
function(_, y)
9-
return NVIM9.ops["EqualTo"](y, 2)
10-
end,
11-
}, { replace = 0 })
125

136
it("Test_method_comments", function()
147
-- Set errors to empty

lua/vim9script/fn.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ readdirex({directory} [, {expr} [, {dict}]]) *readdirex()*
102102
itself because of performance reasons.
103103
--]=]
104104
fn.readdirex = function(dir)
105-
print("DIR:", vim.inspect(dir))
106105
local files = vim.fn.readdir(dir)
107106
local direx = {}
108107
for _, f in ipairs(files) do
@@ -119,6 +118,19 @@ fn.mapnew = function(tbl, expr)
119118
return vim.fn.map(tbl, expr)
120119
end
121120

121+
fn.typename = function(val)
122+
local ty = type(val)
123+
if ty == "string" then
124+
return "string"
125+
elseif ty == "boolean" then
126+
return "bool"
127+
elseif ty == "number" then
128+
return "number"
129+
else
130+
error(string.format("typename: %s", val))
131+
end
132+
end
133+
122134
-- Popup menu stuff
123135

124136
do
@@ -131,7 +143,6 @@ do
131143

132144
fn.popup_menu = function(what, options)
133145
-- print "OPTIONS:"
134-
-- P(options)
135146

136147
local buf = vim.api.nvim_create_buf(false, true)
137148
local win = vim.api.nvim_open_win(buf, true, {

lua/vim9script/init.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ M.slice = function(obj, start, finish)
115115
error("invalid type for slicing: " .. vim.inspect(obj))
116116
end
117117

118-
print("OBJ:", obj)
119-
print("START", start)
120-
print("FINISH", finish)
121118
return slicer(obj, start + 1, finish + 1)
122119
end
123120

0 commit comments

Comments
 (0)