compiler: make compiler an ordinary vlib/compiler module

* Move compiler/ under vlib/compiler/ .

* Add a minimal compiler/main.v driver program.

* Cleanup compiler/main.v .

* Make most compiler tests pass again.

* Apply the fix by @joe-conigliaro , so that the rest of the compiler tests are fixed too.

* Thanks to @avitkauskas, now the vlib/vcompiler/tests/str_gen_test.v test does not need to be special cased anymore.

* Reapply @joe-conigliaro fix for vgen.
pull/2325/head^2
Delyan Angelov 2019-10-13 16:37:43 +03:00 committed by Alexander Medvednikov
parent 59d4535f84
commit 53c64abdeb
71 changed files with 1095 additions and 1080 deletions

1060
compiler/main.v 100644 → 100755

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import ( import (
os os

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import os import os

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import os import os

View File

@ -1,4 +1,4 @@
module main module compiler
const ( const (

View File

@ -1,4 +1,4 @@
module main module compiler
import ( import (
os os

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import ( import (
vweb.tmpl // for `$vweb_html()` vweb.tmpl // for `$vweb_html()`

View File

@ -5,7 +5,7 @@
// Directed acyclic graph // Directed acyclic graph
// this implementation is specifically suited to ordering dependencies // this implementation is specifically suited to ordering dependencies
module main module compiler
struct DepGraphNode { struct DepGraphNode {
mut: mut:

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import( import(
strings strings

View File

@ -1,4 +1,4 @@
module main module compiler
import strings import strings

View File

@ -1,4 +1,4 @@
module main module compiler
import strings import strings

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
// TODO replace with comptime code generation. // TODO replace with comptime code generation.
// TODO remove cJSON dependency. // TODO remove cJSON dependency.

View File

@ -1,4 +1,4 @@
module main module compiler
import os import os
import time import time

1043
vlib/compiler/main.v 100644

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import ( import (
strings strings

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import os import os

View File

@ -1,4 +1,4 @@
module main module compiler
import os import os

View File

@ -1,4 +1,4 @@
module main module compiler
// `a in [1,2,3]` => `a == 1 || a == 2 || a == 3` // `a in [1,2,3]` => `a == 1 || a == 2 || a == 3`
// avoid allocation // avoid allocation

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import ( import (
os os
@ -2183,7 +2183,7 @@ struct $f.parent_fn {
', fname_tidx) ', fname_tidx)
} }
// Don't allow `arr.data` // Don't allow `arr.data`
if field.access_mod == .private && !p.builtin_mod && !p.pref.translated && p.mod != typ.mod { if field.access_mod == .private && !p.builtin_mod && !p.pref.translated && p.mod != typ.mod && p.file_path_id != 'vgen' {
// println('$typ.name :: $field.name ') // println('$typ.name :: $field.name ')
// println(field.access_mod) // println(field.access_mod)
p.error_with_token_index('cannot refer to unexported field `$struct_field` (type `$typ.name`)', fname_tidx) p.error_with_token_index('cannot refer to unexported field `$struct_field` (type `$typ.name`)', fname_tidx)

View File

@ -1,4 +1,4 @@
module main module compiler
import strings import strings

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import strings import strings

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import os import os
import term import term
@ -58,7 +58,7 @@ fn (r &Repl) function_call(line string) bool {
return false return false
} }
fn repl_help() { pub fn repl_help() {
version_hash := vhash() version_hash := vhash()
println(' println('
V $Version $version_hash V $Version $version_hash
@ -68,7 +68,7 @@ V $Version $version_hash
') ')
} }
fn run_repl() []string { pub fn run_repl() []string {
version_hash := vhash() version_hash := vhash()
println('V $Version $version_hash') println('V $Version $version_hash')
println('Use Ctrl-C or `exit` to exit') println('Use Ctrl-C or `exit` to exit')

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import ( import (
os os

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import os import os
import math import math

View File

@ -1,6 +1,6 @@
module main module main
import compiler.tests.repl.runner import vcompiler.tests.repl.runner
import log import log
import benchmark import benchmark

View File

@ -11,7 +11,7 @@ pub:
pub fn full_path_to_v() string { pub fn full_path_to_v() string {
vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' } vname := if os.user_os() == 'windows' { 'v.exe' } else { 'v' }
vexec := os.dir(os.dir(os.dir(os.dir( os.executable() )))) + os.path_separator + vname vexec := os.dir(os.dir(os.dir(os.dir(os.dir( os.executable() ))))) + os.path_separator + vname
/* /*
args := os.args args := os.args
vreal := os.realpath('v') vreal := os.realpath('v')

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
enum TokenKind { enum TokenKind {
eof eof

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by an MIT license // Use of this source code is governed by an MIT license
// that can be found in the LICENSE file. // that can be found in the LICENSE file.
module main module compiler
import strings import strings

View File

@ -1,4 +1,4 @@
module main module compiler
const ( const (
HelpText = 'Usage: v [options/commands] [file.v | directory] HelpText = 'Usage: v [options/commands] [file.v | directory]

View File

@ -1,4 +1,4 @@
module main module compiler
import ( import (
os os
@ -15,14 +15,14 @@ mut:
benchmark benchmark.Benchmark benchmark benchmark.Benchmark
} }
fn new_test_sesion(vargs string) TestSession { pub fn new_test_sesion(vargs string) TestSession {
return TestSession{ return TestSession{
vexe: os.executable() vexe: os.executable()
vargs: vargs vargs: vargs
} }
} }
fn test_v() { pub fn test_v() {
args := os.args args := os.args
if args.last() == 'test' { if args.last() == 'test' {
println('Usage:') println('Usage:')
@ -71,7 +71,7 @@ fn test_v() {
} }
} }
fn (ts mut TestSession) test() { pub fn (ts mut TestSession) test() {
ok := term.ok_message('OK') ok := term.ok_message('OK')
fail := term.fail_message('FAIL') fail := term.fail_message('FAIL')
cmd_needs_quoting := (os.user_os() == 'windows') cmd_needs_quoting := (os.user_os() == 'windows')
@ -121,7 +121,7 @@ fn stable_example(example string, index int, arr []string) bool {
return !example.contains('vweb') return !example.contains('vweb')
} }
fn v_test_v(args_before_test string){ pub fn v_test_v(args_before_test string){
vexe := os.executable() vexe := os.executable()
parent_dir := os.dir(vexe) parent_dir := os.dir(vexe)
// Changing the current directory is needed for some of the compiler tests, // Changing the current directory is needed for some of the compiler tests,
@ -165,7 +165,7 @@ fn v_test_v(args_before_test string){
} }
} }
fn test_vget() { pub fn test_vget() {
/* /*
vexe := os.executable() vexe := os.executable()
ret := os.system('$vexe install nedpals.args') ret := os.system('$vexe install nedpals.args')