mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
pref: fix unintended file extensions in default output names, allow for v run file.c.v
(#19745)
This commit is contained in:
parent
72ba6c2d46
commit
e34e06350a
6 changed files with 36 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -130,3 +130,4 @@ vls.log
|
||||||
wasm.v
|
wasm.v
|
||||||
TAGS
|
TAGS
|
||||||
tags
|
tags
|
||||||
|
vlib/builtin/js/*.js
|
||||||
|
|
|
@ -113,6 +113,12 @@ fn get_all_commands() []Command {
|
||||||
runcmd: .execute
|
runcmd: .execute
|
||||||
expect: "['arg1', 'arg2']1.0"
|
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 {
|
$if linux || macos {
|
||||||
res << Command{
|
res << Command{
|
||||||
line: '${vexe} run examples/hello_world.v'
|
line: '${vexe} run examples/hello_world.v'
|
||||||
|
|
7
examples/call_c_from_v/main.c.v
Normal file
7
examples/call_c_from_v/main.c.v
Normal file
|
@ -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.')
|
||||||
|
}
|
|
@ -108,9 +108,11 @@ pub fn (x u16) hex() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (x i8) hex() string {
|
pub fn (x i8) hex() string {
|
||||||
res := ''
|
mut res := ''
|
||||||
#res.str = x.val.toString(16)
|
#res.str = x.val.toString(16)
|
||||||
|
if res.len < 2 {
|
||||||
|
res = '0' + res
|
||||||
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,9 +138,11 @@ pub fn (x int_literal) hex() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (x u8) hex() string {
|
pub fn (x u8) hex() string {
|
||||||
res := ''
|
mut res := ''
|
||||||
#res.str = x.val.toString(16)
|
#res.str = x.val.toString(16)
|
||||||
|
if res.len < 2 {
|
||||||
|
res = '0' + res
|
||||||
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ fn test_hex() {
|
||||||
// assert u64(-1).hex() == 'ffffffffffffffff'
|
// assert u64(-1).hex() == 'ffffffffffffffff'
|
||||||
// signed tests
|
// signed tests
|
||||||
// assert i8(-1).hex() == 'ff'
|
// assert i8(-1).hex() == 'ff'
|
||||||
assert i8(12).hex() == 'c'
|
assert i8(12).hex() == '0c'
|
||||||
assert i16(32767).hex() == '7fff'
|
assert i16(32767).hex() == '7fff'
|
||||||
assert int(2147483647).hex() == '7fffffff'
|
assert int(2147483647).hex() == '7fffffff'
|
||||||
assert i64(9223372036854775807).hex() == '7fffffffffffffff'
|
assert i64(9223372036854775807).hex() == '7fffffffffffffff'
|
||||||
|
@ -202,35 +202,35 @@ fn test_int_to_hex() {
|
||||||
st1 := [u8(0x41)].repeat(100)
|
st1 := [u8(0x41)].repeat(100)
|
||||||
assert st1.hex() == '41'.repeat(100)*/
|
assert st1.hex() == '41'.repeat(100)*/
|
||||||
// --- int to hex tests
|
// --- int to hex tests
|
||||||
c0 := 12
|
c := 12
|
||||||
// 8Bit
|
// 8Bit
|
||||||
assert u8(0).hex() == '0'
|
assert u8(0).hex() == '00'
|
||||||
assert u8(c0).hex() == 'c'
|
assert u8(c).hex() == '0c'
|
||||||
assert i8(c0).hex() == 'c'
|
assert i8(c).hex() == '0c'
|
||||||
assert u8(127).hex() == '7f'
|
assert u8(127).hex() == '7f'
|
||||||
assert i8(127).hex() == '7f'
|
assert i8(127).hex() == '7f'
|
||||||
assert u8(255).hex() == 'ff'
|
assert u8(255).hex() == 'ff'
|
||||||
// assert u8(-1).hex() == 'ff'
|
// assert u8(-1).hex() == 'ff'
|
||||||
// 16bit
|
// 16bit
|
||||||
assert u16(0).hex() == '0'
|
assert u16(0).hex() == '0'
|
||||||
assert i16(c0).hex() == 'c'
|
assert i16(c).hex() == 'c'
|
||||||
assert u16(c0).hex() == 'c'
|
assert u16(c).hex() == 'c'
|
||||||
assert i16(32767).hex() == '7fff'
|
assert i16(32767).hex() == '7fff'
|
||||||
assert u16(32767).hex() == '7fff'
|
assert u16(32767).hex() == '7fff'
|
||||||
// assert i16(-1).hex() == 'ffff'
|
// assert i16(-1).hex() == 'ffff'
|
||||||
assert u16(65535).hex() == 'ffff'
|
assert u16(65535).hex() == 'ffff'
|
||||||
// 32bit
|
// 32bit
|
||||||
assert u32(0).hex() == '0'
|
assert u32(0).hex() == '0'
|
||||||
assert c0.hex() == 'c'
|
assert c.hex() == 'c'
|
||||||
assert u32(c0).hex() == 'c'
|
assert u32(c).hex() == 'c'
|
||||||
assert 2147483647.hex() == '7fffffff'
|
assert 2147483647.hex() == '7fffffff'
|
||||||
assert u32(2147483647).hex() == '7fffffff'
|
assert u32(2147483647).hex() == '7fffffff'
|
||||||
// assert (-1).hex() == 'ffffffffffffffff'
|
// assert (-1).hex() == 'ffffffffffffffff'
|
||||||
// assert u32(4294967295).hex() == 'ffffffff'
|
// assert u32(4294967295).hex() == 'ffffffff'
|
||||||
// 64 bit
|
// 64 bit
|
||||||
assert u64(0).hex() == '0'
|
assert u64(0).hex() == '0'
|
||||||
assert i64(c0).hex() == 'c'
|
assert i64(c).hex() == 'c'
|
||||||
assert u64(c0).hex() == 'c'
|
assert u64(c).hex() == 'c'
|
||||||
assert i64(9223372036854775807).hex() == '7fffffffffffffff'
|
assert i64(9223372036854775807).hex() == '7fffffffffffffff'
|
||||||
assert u64(9223372036854775807).hex() == '7fffffffffffffff'
|
assert u64(9223372036854775807).hex() == '7fffffffffffffff'
|
||||||
// assert i64(-1).hex() == 'ffffffffffffffff'
|
// assert i64(-1).hex() == 'ffffffffffffffff'
|
||||||
|
|
|
@ -63,6 +63,9 @@ pub fn (mut p Preferences) fill_with_defaults() {
|
||||||
if p.out_name == '' {
|
if p.out_name == '' {
|
||||||
filename := os.file_name(rpath).trim_space()
|
filename := os.file_name(rpath).trim_space()
|
||||||
mut base := filename.all_before_last('.')
|
mut base := filename.all_before_last('.')
|
||||||
|
if os.file_ext(base) in ['.c', '.js', '.wasm'] {
|
||||||
|
base = base.all_before_last('.')
|
||||||
|
}
|
||||||
if base == '' {
|
if base == '' {
|
||||||
// The file name is just `.v` or `.vsh` or `.*`
|
// The file name is just `.v` or `.vsh` or `.*`
|
||||||
base = filename
|
base = filename
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue