Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pref: fix unintended file extensions in default output names #19745

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ vls.log
wasm.v
TAGS
tags
vlib/builtin/js/*.js
6 changes: 6 additions & 0 deletions cmd/tools/vtest-all.v
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ fn get_all_commands() []Command {
runcmd: .execute
expect: "['arg1', 'arg2']1.0"
}
res << Command{
line: '${vexe} -o calling_c.exe run examples/call_c_from_v/main.c.v'
okmsg: 'V can run main.c.v files'
runcmd: .execute
contains: 'V can call C functions like puts too.'
}
$if linux || macos {
res << Command{
line: '${vexe} run examples/hello_world.v'
Expand Down
7 changes: 7 additions & 0 deletions examples/call_c_from_v/main.c.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

fn C.puts(&char) int

fn main() {
C.puts(c'V can call C functions like `puts` too.')
}
12 changes: 8 additions & 4 deletions vlib/builtin/js/int.js.v
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ pub fn (x u16) hex() string {
}

pub fn (x i8) hex() string {
res := ''
mut res := ''
#res.str = x.val.toString(16)

if res.len < 2 {
res = '0' + res
}
return res
}

Expand All @@ -136,9 +138,11 @@ pub fn (x int_literal) hex() string {
}

pub fn (x u8) hex() string {
res := ''
mut res := ''
#res.str = x.val.toString(16)

if res.len < 2 {
res = '0' + res
}
return res
}

Expand Down
22 changes: 11 additions & 11 deletions vlib/builtin/js/int_test.js.v
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn test_hex() {
// assert u64(-1).hex() == 'ffffffffffffffff'
// signed tests
// assert i8(-1).hex() == 'ff'
assert i8(12).hex() == 'c'
assert i8(12).hex() == '0c'
assert i16(32767).hex() == '7fff'
assert int(2147483647).hex() == '7fffffff'
assert i64(9223372036854775807).hex() == '7fffffffffffffff'
Expand Down Expand Up @@ -202,35 +202,35 @@ fn test_int_to_hex() {
st1 := [u8(0x41)].repeat(100)
assert st1.hex() == '41'.repeat(100)*/
// --- int to hex tests
c0 := 12
c := 12
// 8Bit
assert u8(0).hex() == '0'
assert u8(c0).hex() == 'c'
assert i8(c0).hex() == 'c'
assert u8(0).hex() == '00'
assert u8(c).hex() == '0c'
assert i8(c).hex() == '0c'
assert u8(127).hex() == '7f'
assert i8(127).hex() == '7f'
assert u8(255).hex() == 'ff'
// assert u8(-1).hex() == 'ff'
// 16bit
assert u16(0).hex() == '0'
assert i16(c0).hex() == 'c'
assert u16(c0).hex() == 'c'
assert i16(c).hex() == 'c'
assert u16(c).hex() == 'c'
assert i16(32767).hex() == '7fff'
assert u16(32767).hex() == '7fff'
// assert i16(-1).hex() == 'ffff'
assert u16(65535).hex() == 'ffff'
// 32bit
assert u32(0).hex() == '0'
assert c0.hex() == 'c'
assert u32(c0).hex() == 'c'
assert c.hex() == 'c'
assert u32(c).hex() == 'c'
assert 2147483647.hex() == '7fffffff'
assert u32(2147483647).hex() == '7fffffff'
// assert (-1).hex() == 'ffffffffffffffff'
// assert u32(4294967295).hex() == 'ffffffff'
// 64 bit
assert u64(0).hex() == '0'
assert i64(c0).hex() == 'c'
assert u64(c0).hex() == 'c'
assert i64(c).hex() == 'c'
assert u64(c).hex() == 'c'
assert i64(9223372036854775807).hex() == '7fffffffffffffff'
assert u64(9223372036854775807).hex() == '7fffffffffffffff'
// assert i64(-1).hex() == 'ffffffffffffffff'
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/pref/default.v
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub fn (mut p Preferences) fill_with_defaults() {
if p.out_name == '' {
filename := os.file_name(rpath).trim_space()
mut base := filename.all_before_last('.')
if os.file_ext(base) in ['.c', '.js', '.wasm'] {
base = base.all_before_last('.')
}
if base == '' {
// The file name is just `.v` or `.vsh` or `.*`
base = filename
Expand Down
Loading