v script
parent
55b8a9acb9
commit
b9f3f2d622
|
@ -67,6 +67,7 @@ mut:
|
||||||
is_c_struct_init bool
|
is_c_struct_init bool
|
||||||
can_chash bool
|
can_chash bool
|
||||||
attr string
|
attr string
|
||||||
|
v_script bool // "V bash", import all os functions into global space
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -1258,6 +1259,14 @@ fn (p mut Parser) bterm() string {
|
||||||
case Token.gt: p.cgen.set_placeholder(ph, 'string_gt(')
|
case Token.gt: p.cgen.set_placeholder(ph, 'string_gt(')
|
||||||
case Token.lt: p.cgen.set_placeholder(ph, 'string_lt(')
|
case Token.lt: p.cgen.set_placeholder(ph, 'string_lt(')
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
Token.eq => p.cgen.set_placeholder(ph, 'string_eq(')
|
||||||
|
Token.ne => p.cgen.set_placeholder(ph, 'string_ne(')
|
||||||
|
Token.le => p.cgen.set_placeholder(ph, 'string_le(')
|
||||||
|
Token.ge => p.cgen.set_placeholder(ph, 'string_ge(')
|
||||||
|
Token.gt => p.cgen.set_placeholder(ph, 'string_gt(')
|
||||||
|
Token.lt => p.cgen.set_placeholder(ph, 'string_lt(')
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return typ
|
return typ
|
||||||
|
@ -1442,23 +1451,31 @@ fn (p mut Parser) name_expr() string {
|
||||||
return typ
|
return typ
|
||||||
}
|
}
|
||||||
// Function (not method btw, methods are handled in dot())
|
// Function (not method btw, methods are handled in dot())
|
||||||
f := p.table.find_fn(name)
|
mut f := p.table.find_fn(name)
|
||||||
if f.name == '' {
|
if f.name == '' {
|
||||||
// We are in a second pass, that means this function was not defined, throw an error.
|
// We are in a second pass, that means this function was not defined, throw an error.
|
||||||
if !p.first_run() {
|
if !p.first_run() {
|
||||||
// If orig_name is a pkg, then printing undefined: `pkg` tells us nothing
|
// V script? Try os module.
|
||||||
// if p.table.known_pkg(orig_name) {
|
if p.v_script {
|
||||||
if p.table.known_pkg(orig_name) || p.import_table.known_alias(orig_name) {
|
name = name.replace('main__', 'os__')
|
||||||
name = name.replace('__', '.').replace('_dot_', '.')
|
f = p.table.find_fn(name)
|
||||||
p.error('undefined: `$name`')
|
}
|
||||||
}
|
if f.name == '' {
|
||||||
else {
|
// If orig_name is a pkg, then printing undefined: `pkg` tells us nothing
|
||||||
p.error('undefined: `$orig_name`')
|
// if p.table.known_pkg(orig_name) {
|
||||||
}
|
if p.table.known_pkg(orig_name) || p.import_table.known_alias(orig_name) {
|
||||||
}
|
name = name.replace('__', '.').replace('_dot_', '.')
|
||||||
p.next()
|
p.error('undefined: `$name`')
|
||||||
// First pass, the function can be defined later.
|
}
|
||||||
return 'void'
|
else {
|
||||||
|
p.error('undefined: `$orig_name`')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p.next()
|
||||||
|
// First pass, the function can be defined later.
|
||||||
|
return 'void'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// no () after func, so func is an argument, just gen its name
|
// no () after func, so func is an argument, just gen its name
|
||||||
// TODO verify this and handle errors
|
// TODO verify this and handle errors
|
||||||
|
@ -2770,6 +2787,10 @@ fn (p mut Parser) chash() {
|
||||||
// Move defines on top
|
// Move defines on top
|
||||||
p.cgen.includes << '#$hash'
|
p.cgen.includes << '#$hash'
|
||||||
}
|
}
|
||||||
|
else if hash == 'v' {
|
||||||
|
println('v script')
|
||||||
|
//p.v_script = true
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
if !p.can_chash {
|
if !p.can_chash {
|
||||||
p.error('bad token `#` (embedding C code is no longer supported)')
|
p.error('bad token `#` (embedding C code is no longer supported)')
|
||||||
|
|
11
vlib/os/os.v
11
vlib/os/os.v
|
@ -483,16 +483,17 @@ pub fn user_os() string {
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
// hostname returns hostname
|
|
||||||
|
// hostname returns the host name reported by the kernel.
|
||||||
pub fn hostname() ?string {
|
pub fn hostname() ?string {
|
||||||
mut hname := [256]byte
|
mut name := [256]byte
|
||||||
// https://www.ietf.org/rfc/rfc1035.txt
|
// https://www.ietf.org/rfc/rfc1035.txt
|
||||||
// The host name is returned as a null-terminated string.
|
// The host name is returned as a null-terminated string.
|
||||||
res := C.gethostname(&hname, 256)
|
res := C.gethostname(&name, 256)
|
||||||
if res != 0 {
|
if res != 0 {
|
||||||
return error('os: hostname cannot get host name of PC.')
|
return error('os.hostname() cannot get the host name')
|
||||||
}
|
}
|
||||||
return tos_clone(hname)
|
return tos_clone(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// home_dir returns path to user's home directory.
|
// home_dir returns path to user's home directory.
|
||||||
|
|
Loading…
Reference in New Issue