Skip to content

Commit

Permalink
better main + ci (#22)
Browse files Browse the repository at this point in the history
add ci and possibly a release workflow
  • Loading branch information
tjdevries authored Jan 12, 2023
1 parent 5ac5752 commit af7d608
Show file tree
Hide file tree
Showing 16 changed files with 303 additions and 261 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
on: [push]

name: build-and-test

jobs:
check:
name: Build and Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install Neovim
shell: bash
run: |
wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.deb -O /tmp/nvim.deb
sudo dpkg -i /tmp/nvim.deb
- name: Install plenary.nvim (for testing)
run: |
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
- name: Install latest nightly rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy

- name: Run cargo clippy (workspace)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --workspace

- name: Run cargo build (workspace)
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: release-tag

on:
push:
tags:
- v*


jobs:
release-image:
name: Release latest version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install latest nightly rust
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
components: rustfmt, clippy

- name: Run cargo build --release (workspace)
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace --release

- uses: "marvinpinto/action-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
prerelease: false
title: "Latest Release"
files: |
./target/release/vim9jit
4 changes: 2 additions & 2 deletions crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ impl VisitMut for ReplaceQuestions {
#[proc_macro_attribute]
pub fn parse_context(_attr: TokenStream, tokens: TokenStream) -> TokenStream {
let mut input = parse_macro_input!(tokens as syn::ItemImpl);
for mut item in input.items.iter_mut() {
for item in input.items.iter_mut() {
match &item {
ImplItem::Const(_) => todo!(),
ImplItem::Method(_) => {
let mut replacer = ReplaceQuestions {
name: *input.self_ty.clone(),
};

replacer.visit_impl_item_mut(&mut item);
replacer.visit_impl_item_mut(item);
}
ImplItem::Type(_) => todo!(),
ImplItem::Macro(_) => todo!(),
Expand Down
20 changes: 7 additions & 13 deletions crates/vim9-gen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ fn main() -> anyhow::Result<()> {

let source_lua = Path::new("src/lua");
let mut entries = Vec::new();
for entry in source_lua.read_dir().unwrap() {
if let Ok(entry) = entry {
entries.push(entry.path());
}
for entry in source_lua.read_dir().unwrap().flatten() {
entries.push(entry.path());
}

// always sort `init` to the top of the list
Expand Down Expand Up @@ -68,23 +66,19 @@ fn main() -> anyhow::Result<()> {
let contents = contents.replace("require \"_vim9script\"", "vim9");

if name == "_" {
writeln!(&mut file, "{}\n", contents)?;
writeln!(&mut file, "{contents}\n")?;
} else if name == "init" {
// init.lua declares our base module and it's guaranteed to be first.
writeln!(&mut file, "local vim9 = (function() {} end)()\n", contents)?;
writeln!(&mut file, "local vim9 = (function() {contents} end)()\n")?;
} else {
writeln!(
&mut file,
"vim9['{}'] = (function() {} end)()",
name, contents
)?;
writeln!(&mut file, "vim9['{name}'] = (function() {contents} end)()",)?;
}
}

writeln!(&mut file, "")?;
writeln!(&mut file)?;
writeln!(&mut file, "return vim9")?;

let file = format::lua(&file).expect(&format!("to format code: {}", file));
let file = format::lua(&file).expect("to format the file");

let init_lua = luadir.join("_vim9script.lua");
fs::write(init_lua, file)?;
Expand Down
20 changes: 8 additions & 12 deletions crates/vim9-gen/src/call_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ fn expr_is_func_mutable(arg: &Expression) -> bool {
}
}

pub fn mutates(expr: &CallExpression, data: &FunctionData) -> Option<VimFuncMutability> {
match data {
// FunctionData::VimFunc { .. } => return None,
_ => {}
};
pub fn mutates(expr: &CallExpression, _data: &FunctionData) -> Option<VimFuncMutability> {
{};

// Check if any args can even be mutated
// If there are none, then it doesn't matter if the function
Expand Down Expand Up @@ -162,7 +159,7 @@ impl VimFunc {
// })
// .collect::<Vec<_>>();

generate_mutable_fn_call(&name, &args, &replaced)
generate_mutable_fn_call(name, &args, &replaced)
}
}

Expand Down Expand Up @@ -230,8 +227,8 @@ impl Generate for Vec<Expression> {
pub fn generate(call: &CallExpression, state: &mut State) -> String {
let func_data: FunctionData = call.into();

match mutates(call, &func_data) {
Some(mutability) => match func_data {
if let Some(mutability) = mutates(call, &func_data) {
match func_data {
FunctionData::ApiFunc { .. } => {}
FunctionData::GeneratedFunc { .. } => {}
FunctionData::VimFuncRef { .. } => todo!(),
Expand All @@ -242,8 +239,7 @@ pub fn generate(call: &CallExpression, state: &mut State) -> String {
// but at the same time, it's nice to just assume that functions
// that are expressions are really just generated funcs
FunctionData::ExprFunc { .. } => {}
},
None => {}
}
};

match func_data {
Expand Down Expand Up @@ -294,7 +290,7 @@ end
}

fn generate_mutable_fn_call(name: &str, args: &str, replace: &str) -> String {
return format!("vim9.fn_mut('{name}', {{ {args} }}, {{ replace = {replace} }})");
format!("vim9.fn_mut('{name}', {{ {args} }}, {{ replace = {replace} }})")
}

pub fn generate_method(method: &parser::MethodCall, state: &mut State) -> String {
Expand All @@ -320,7 +316,7 @@ pub fn generate_method(method: &parser::MethodCall, state: &mut State) -> String
let name = func_data.name();
let args = call.args.gen(state);
let replace = mutability.returned.unwrap().to_string();
return generate_mutable_fn_call(&name, &args, &replace);
return generate_mutable_fn_call(name, &args, &replace);
}
}
}
Expand Down
Loading

0 comments on commit af7d608

Please sign in to comment.