repl: add more stats and tests; compiler: tcc fixes
parent
ff4ef337da
commit
854de4e7e0
|
@ -30,6 +30,9 @@ fn (v V) get_os_cflags() []CFlag {
|
||||||
// format flag
|
// format flag
|
||||||
fn (cf &CFlag) format() string {
|
fn (cf &CFlag) format() string {
|
||||||
mut value := cf.value
|
mut value := cf.value
|
||||||
|
if cf.name == '-l' && value.len>0 {
|
||||||
|
return '${cf.name}${value}'.trim_space()
|
||||||
|
}
|
||||||
// convert to absolute path
|
// convert to absolute path
|
||||||
if cf.name == '-I' || cf.name == '-L' || value.ends_with('.o') {
|
if cf.name == '-I' || cf.name == '-L' || value.ends_with('.o') {
|
||||||
value = '"'+os.realpath(value)+'"'
|
value = '"'+os.realpath(value)+'"'
|
||||||
|
|
|
@ -38,12 +38,8 @@ CommonCHeaders = '
|
||||||
#include <sys/wait.h> // os__wait uses wait on nix
|
#include <sys/wait.h> // os__wait uses wait on nix
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define EMPTY_STRUCT_DECLARATION
|
#define EMPTY_STRUCT_DECLARATION
|
||||||
#ifdef _MSC_VER
|
#define EMPTY_STRUCT_INITIALIZATION
|
||||||
#define EMPTY_STRUCT_DECLARATION int:0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define OPTION_CAST(x) (x)
|
#define OPTION_CAST(x) (x)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -65,9 +61,11 @@ CommonCHeaders = '
|
||||||
|
|
||||||
// MSVC cannot parse some things properly
|
// MSVC cannot parse some things properly
|
||||||
#undef EMPTY_STRUCT_DECLARATION
|
#undef EMPTY_STRUCT_DECLARATION
|
||||||
#define EMPTY_STRUCT_DECLARATION void *____dummy_variable
|
#undef EMPTY_STRUCT_INITIALIZATION
|
||||||
|
|
||||||
#undef OPTION_CAST
|
#undef OPTION_CAST
|
||||||
|
|
||||||
|
#define EMPTY_STRUCT_DECLARATION int ____dummy_variable
|
||||||
|
#define EMPTY_STRUCT_INITIALIZATION 0
|
||||||
#define OPTION_CAST(x)
|
#define OPTION_CAST(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -330,7 +330,7 @@ fn (p mut Parser) gen_struct_init(typ string, t Type) bool {
|
||||||
else {
|
else {
|
||||||
p.gen('($typ) {')
|
p.gen('($typ) {')
|
||||||
if t.fields.len == 1 && t.fields[0].name == '' && t.fields[0].typ.starts_with('EMPTY_STRUCT_DECLARATION') {
|
if t.fields.len == 1 && t.fields[0].name == '' && t.fields[0].typ.starts_with('EMPTY_STRUCT_DECLARATION') {
|
||||||
p.gen(' 0 /* v empty struct initialization */ ')
|
p.gen(' EMPTY_STRUCT_INITIALIZATION ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,17 @@
|
||||||
- Add `===output===`
|
- Add `===output===`
|
||||||
- Write the output expected
|
- Write the output expected
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
Keep in mind, that the way V repl works for now, every non empty line
|
||||||
|
would cause a new recompilation of the entire repl content that was
|
||||||
|
collected so far.
|
||||||
|
|
||||||
|
*Longer REPL files would cause measurably*
|
||||||
|
*longer recompilation/testing times.*
|
||||||
|
|
||||||
|
Also, longer repl files would be slower to debug when they fail,
|
||||||
|
*It is better to have several smaller files vs one huge REPL file.*
|
||||||
|
|
||||||
### Example :
|
### Example :
|
||||||
```
|
```
|
||||||
a := 1
|
a := 1
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
struct A { mut: v int } struct B { a A } struct C { mut: b B } struct D { mut: c C } struct E { mut: v []int } struct F { e []E }
|
||||||
|
|
||||||
|
mut b := B{} b = B{A{2}}
|
||||||
|
println('b is: ' + b.a.v.str())
|
||||||
|
|
||||||
|
mut c := C{} c.b = B{}
|
||||||
|
|
||||||
|
mut d := D{} d.c.b = B{}
|
||||||
|
|
||||||
|
f := F{[E{[10,20,30]},E{[100,200,300,400]}]}
|
||||||
|
println('f.e[0].v.len: ${f.e[0].v.len}')
|
||||||
|
println('f.e[1].v.len: ${f.e[1].v.len}')
|
||||||
|
===output===
|
||||||
|
b is: 2
|
||||||
|
f.e[0].v.len: 3
|
||||||
|
f.e[1].v.len: 4
|
|
@ -0,0 +1,4 @@
|
||||||
|
struct Empty{} ee := Empty{}
|
||||||
|
println('OK')
|
||||||
|
===output===
|
||||||
|
OK
|
|
@ -0,0 +1,30 @@
|
||||||
|
mut s := 'hello world'
|
||||||
|
s.len = 0 // Error (field len immutable)
|
||||||
|
|
||||||
|
mut a := []string
|
||||||
|
a.len = 0 // Error (field len immutable)
|
||||||
|
|
||||||
|
mut ints := []int
|
||||||
|
ints.len = 0 // Error (field len immutable)
|
||||||
|
|
||||||
|
println('BYE')
|
||||||
|
===output===
|
||||||
|
.vrepl_temp.v:2:5: cannot modify immutable field `len` (type `string`)
|
||||||
|
declare the field with `mut:`
|
||||||
|
struct string {
|
||||||
|
mut:
|
||||||
|
len int
|
||||||
|
}
|
||||||
|
.vrepl_temp.v:3:5: cannot modify immutable field `len` (type `array`)
|
||||||
|
declare the field with `mut:`
|
||||||
|
struct array {
|
||||||
|
mut:
|
||||||
|
len int
|
||||||
|
}
|
||||||
|
.vrepl_temp.v:4:8: cannot modify immutable field `len` (type `array`)
|
||||||
|
declare the field with `mut:`
|
||||||
|
struct array {
|
||||||
|
mut:
|
||||||
|
len int
|
||||||
|
}
|
||||||
|
BYE
|
|
@ -21,16 +21,23 @@ fn test_the_v_compiler_can_be_invoked() {
|
||||||
fn test_all_v_repl_files() {
|
fn test_all_v_repl_files() {
|
||||||
options := runner.new_options()
|
options := runner.new_options()
|
||||||
global_start_time := runner.now()
|
global_start_time := runner.now()
|
||||||
|
mut total_tests := 0
|
||||||
|
mut ok_tests := 0
|
||||||
|
mut failed_tests := 0
|
||||||
for file in options.files {
|
for file in options.files {
|
||||||
|
total_tests++
|
||||||
sticks := runner.now()
|
sticks := runner.now()
|
||||||
fres := runner.run_repl_file(options.wd, options.vexec, file) or {
|
fres := runner.run_repl_file(options.wd, options.vexec, file) or {
|
||||||
|
failed_tests++
|
||||||
assert false
|
assert false
|
||||||
eprintln( runner.tdiff_in_ms(err, sticks) )
|
eprintln( runner.tdiff_in_ms(err, sticks) )
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
assert true
|
assert true
|
||||||
println( runner.tdiff_in_ms(fres, sticks) )
|
println( runner.tdiff_in_ms(fres, sticks) )
|
||||||
|
ok_tests++
|
||||||
}
|
}
|
||||||
println( runner.tdiff_in_ms('<=== total time spent running REPL files', global_start_time) )
|
println( runner.tdiff_in_ms('<=== total time spent running REPL files', global_start_time) )
|
||||||
|
println( ' ok, failed, total : ${ok_tests:5d}, ${failed_tests:5d}, ${total_tests:5d}' )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue