mirror of
https://github.com/vlang/v.git
synced 2025-09-13 06:22:26 +03:00
all: update attributes to use new syntax
This commit is contained in:
parent
dd81cb98c6
commit
757929392e
739 changed files with 2982 additions and 2982 deletions
|
@ -16,7 +16,7 @@ const (
|
|||
separation_distance = 5.0
|
||||
)
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn main() {
|
||||
mut positions := [boids_count]Vector{}
|
||||
mut velocities := [boids_count]Vector{}
|
||||
|
|
|
@ -40,7 +40,7 @@ mut:
|
|||
nmaxs int // number of maximums to discard
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut result CmdResult) free() {
|
||||
unsafe {
|
||||
result.cmd.free()
|
||||
|
@ -52,7 +52,7 @@ fn (mut result CmdResult) free() {
|
|||
}
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut context Context) free() {
|
||||
unsafe {
|
||||
context.commands.free()
|
||||
|
@ -75,7 +75,7 @@ mut:
|
|||
nmaxs int // number of discarded slowest results
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut a Aints) free() {
|
||||
unsafe { a.values.free() }
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ fn cleanup_tdir() {
|
|||
|
||||
type MyResult = string
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
fn (result MyResult) fail(reason string) {
|
||||
eprintln('> ${reason}, but it does not. Result:\n${result}')
|
||||
exit(1)
|
||||
|
|
|
@ -53,57 +53,57 @@ fn C.cJSON_Delete(voidptr)
|
|||
|
||||
fn C.cJSON_Print(voidptr) &u8
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn create_object() &C.cJSON {
|
||||
return C.cJSON_CreateObject()
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn create_array() &C.cJSON {
|
||||
return C.cJSON_CreateArray()
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn create_string(val string) &C.cJSON {
|
||||
return C.cJSON_CreateString(val.str)
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn create_number(val f64) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn create_bool(val bool) &C.cJSON {
|
||||
return C.cJSON_CreateBool(val)
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn create_true() &C.cJSON {
|
||||
return C.cJSON_CreateTrue()
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn create_false() &C.cJSON {
|
||||
return C.cJSON_CreateFalse()
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn create_null() &C.cJSON {
|
||||
return C.cJSON_CreateNull()
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn delete(b voidptr) {
|
||||
C.cJSON_Delete(b)
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn add_item_to_object(obj &C.cJSON, key string, item &C.cJSON) {
|
||||
C.cJSON_AddItemToObject(obj, key.str, item)
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn add_item_to_array(obj &C.cJSON, item &C.cJSON) {
|
||||
C.cJSON_AddItemToArray(obj, item)
|
||||
}
|
||||
|
|
|
@ -150,13 +150,13 @@ mut:
|
|||
pub type Node = C.cJSON
|
||||
|
||||
// create an object node
|
||||
[inline]
|
||||
@[inline]
|
||||
fn new_object() &Node {
|
||||
return C.cJSON_CreateObject()
|
||||
}
|
||||
|
||||
// add item to object node
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (node &Node) add(key string, child &Node) {
|
||||
if context.hide_names.len > 0 && key in context.hide_names {
|
||||
return
|
||||
|
@ -168,7 +168,7 @@ fn (node &Node) add(key string, child &Node) {
|
|||
}
|
||||
|
||||
// add item to object node
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (node &Node) add_terse(key string, child &Node) {
|
||||
if context.hide_names.len > 0 && key in context.hide_names {
|
||||
return
|
||||
|
@ -177,13 +177,13 @@ fn (node &Node) add_terse(key string, child &Node) {
|
|||
}
|
||||
|
||||
// create an array node
|
||||
[inline]
|
||||
@[inline]
|
||||
fn new_array() &Node {
|
||||
return C.cJSON_CreateArray()
|
||||
}
|
||||
|
||||
// add item to array node
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (node &Node) add_item(child &Node) {
|
||||
add_item_to_array(node, child)
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ div.products-table {
|
|||
|
||||
import vweb
|
||||
|
||||
['/controller/auth'; post]
|
||||
@['/controller/auth'; post]
|
||||
pub fn (mut app App) controller_auth(username string, password string) vweb.Result {
|
||||
response := app.service_auth(username, password) or {
|
||||
app.set_status(400, '')
|
||||
|
@ -167,8 +167,8 @@ pub fn (mut app App) controller_auth(username string, password string) vweb.Resu
|
|||
content: 'module main
|
||||
|
||||
struct AuthRequestDto {
|
||||
username string [nonull]
|
||||
password string [nonull]
|
||||
username string @[nonull]
|
||||
password string @[nonull]
|
||||
}
|
||||
'
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ import vweb
|
|||
import encoding.base64
|
||||
import json
|
||||
|
||||
['/controller/products'; get]
|
||||
@['/controller/products'; get]
|
||||
pub fn (mut app App) controller_get_all_products() vweb.Result {
|
||||
token := app.req.header.get_custom('token') or { '' }
|
||||
|
||||
|
@ -425,7 +425,7 @@ pub fn (mut app App) controller_get_all_products() vweb.Result {
|
|||
// return app.text('response')
|
||||
}
|
||||
|
||||
['/controller/product/create'; post]
|
||||
@['/controller/product/create'; post]
|
||||
pub fn (mut app App) controller_create_product(product_name string) vweb.Result {
|
||||
if product_name == '' {
|
||||
app.set_status(400, '')
|
||||
|
@ -461,12 +461,12 @@ pub fn (mut app App) controller_create_product(product_name string) vweb.Result
|
|||
path: join_path(c.name, 'src', 'product_entities.v')
|
||||
content: "module main
|
||||
|
||||
[table: 'products']
|
||||
@[table: 'products']
|
||||
struct Product {
|
||||
id int [primary; sql: serial]
|
||||
id int @[primary; sql: serial]
|
||||
user_id int
|
||||
name string [nonull; sql_type: 'TEXT']
|
||||
created_at string [default: 'CURRENT_TIMESTAMP']
|
||||
name string @[nonull; sql_type: 'TEXT']
|
||||
created_at string @[default: 'CURRENT_TIMESTAMP']
|
||||
}
|
||||
"
|
||||
}
|
||||
|
@ -562,7 +562,7 @@ pub fn get_product(token string) ![]User {
|
|||
|
||||
import vweb
|
||||
|
||||
['/products'; get]
|
||||
@['/products'; get]
|
||||
pub fn (mut app App) products() !vweb.Result {
|
||||
token := app.get_cookie('token') or {
|
||||
app.set_status(400, '')
|
||||
|
@ -586,7 +586,7 @@ import vweb
|
|||
import encoding.base64
|
||||
import json
|
||||
|
||||
['/controller/users'; get]
|
||||
@['/controller/users'; get]
|
||||
pub fn (mut app App) controller_get_all_user() vweb.Result {
|
||||
// token := app.get_cookie('token') or { '' }
|
||||
token := app.req.header.get_custom('token') or { '' }
|
||||
|
@ -603,7 +603,7 @@ pub fn (mut app App) controller_get_all_user() vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/controller/user'; get]
|
||||
@['/controller/user'; get]
|
||||
pub fn (mut app App) controller_get_user() vweb.Result {
|
||||
// token := app.get_cookie('token') or { '' }
|
||||
token := app.req.header.get_custom('token') or { '' }
|
||||
|
@ -629,7 +629,7 @@ pub fn (mut app App) controller_get_user() vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/controller/user/create'; post]
|
||||
@['/controller/user/create'; post]
|
||||
pub fn (mut app App) controller_create_user(username string, password string) vweb.Result {
|
||||
if username == '' {
|
||||
app.set_status(400, '')
|
||||
|
@ -652,14 +652,14 @@ pub fn (mut app App) controller_create_user(username string, password string) vw
|
|||
path: join_path(c.name, 'src', 'user_entities.v')
|
||||
content: "module main
|
||||
|
||||
[table: 'users']
|
||||
@[table: 'users']
|
||||
pub struct User {
|
||||
mut:
|
||||
id int [primary; sql: serial]
|
||||
username string [nonull; sql_type: 'TEXT'; unique]
|
||||
password string [nonull; sql_type: 'TEXT']
|
||||
id int @[primary; sql: serial]
|
||||
username string @[nonull; sql_type: 'TEXT'; unique]
|
||||
password string @[nonull; sql_type: 'TEXT']
|
||||
active bool
|
||||
products []Product [fkey: 'user_id']
|
||||
products []Product @[fkey: 'user_id']
|
||||
}
|
||||
"
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ fn clean_line_endings(s string) string {
|
|||
return res
|
||||
}
|
||||
|
||||
[params]
|
||||
@[params]
|
||||
struct CheckOutputParams {
|
||||
program string = 'some/dir/main.v'
|
||||
cmd string = 'v doc'
|
||||
|
|
|
@ -9,7 +9,7 @@ import v.token
|
|||
import strings
|
||||
import v.pref
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn slug(title string) string {
|
||||
return title.replace(' ', '-')
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ enum OutputType {
|
|||
stdout
|
||||
}
|
||||
|
||||
[heap]
|
||||
@[heap]
|
||||
struct VDoc {
|
||||
cfg Config [required]
|
||||
cfg Config @[required]
|
||||
mut:
|
||||
docs []doc.Doc
|
||||
assets map[string]string
|
||||
|
|
|
@ -351,7 +351,7 @@ fn get_compile_name_of_potential_v_project(file string) string {
|
|||
return pfolder
|
||||
}
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
fn verror(s string) {
|
||||
util.verror('vfmt error', s)
|
||||
}
|
||||
|
|
|
@ -418,7 +418,7 @@ fn (upd VlsUpdater) error_details(err IError) string {
|
|||
}
|
||||
}
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
fn (upd VlsUpdater) cli_error(err IError) {
|
||||
match upd.output {
|
||||
.text {
|
||||
|
|
|
@ -39,7 +39,7 @@ mut:
|
|||
exec_err bool
|
||||
}
|
||||
|
||||
[params]
|
||||
@[params]
|
||||
struct ErrorOptions {
|
||||
details string
|
||||
verbose bool // is used to only output the error message if the verbose setting is enabled.
|
||||
|
|
|
@ -64,7 +64,7 @@ struct VFileStat {
|
|||
mtime i64
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut vfs VFileStat) free() {
|
||||
unsafe { vfs.path.free() }
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ mut:
|
|||
only_watch []string // If not empty, *all* files that trigger updates, should match *at least one* of these s.match_glob() patterns. This is also triggered for vweb apps, to monitor for just *.v,*.js,*.css,*.html in vweb projects.
|
||||
}
|
||||
|
||||
[if debug_vwatch ?]
|
||||
@[if debug_vwatch ?]
|
||||
fn (mut context Context) elog(msg string) {
|
||||
eprintln('> vwatch ${context.pid}, ${msg}')
|
||||
}
|
||||
|
|
|
@ -235,9 +235,9 @@ fn (fdr Finder) str() string {
|
|||
|
||||
// Match is one result of the search_for_matches() process
|
||||
struct Match {
|
||||
path string [required]
|
||||
line int [required]
|
||||
text string [required]
|
||||
path string @[required]
|
||||
line int @[required]
|
||||
text string @[required]
|
||||
}
|
||||
|
||||
fn (mtc Match) show() {
|
||||
|
|
|
@ -200,7 +200,7 @@ enum Direction {
|
|||
}
|
||||
|
||||
// Utility functions
|
||||
[inline]
|
||||
@[inline]
|
||||
fn avg(a int, b int) int {
|
||||
return (a + b) / 2
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ fn (mut app App) new_game() {
|
|||
app.new_random_tile()
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) check_for_victory() {
|
||||
for y in 0 .. 4 {
|
||||
for x in 0 .. 4 {
|
||||
|
@ -370,7 +370,7 @@ fn (mut app App) check_for_victory() {
|
|||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) check_for_game_over() {
|
||||
if app.board.is_game_over() {
|
||||
app.state = .over
|
||||
|
@ -547,7 +547,7 @@ fn (app &App) label_format(kind LabelKind) gx.TextCfg {
|
|||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) set_theme(idx int) {
|
||||
theme := themes[idx]
|
||||
app.theme_idx = idx
|
||||
|
@ -761,12 +761,12 @@ fn (mut app App) handle_swipe() {
|
|||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) next_theme() {
|
||||
app.set_theme(if app.theme_idx == themes.len - 1 { 0 } else { app.theme_idx + 1 })
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) next_tile_format() {
|
||||
app.tile_format = unsafe { TileFormat(int(app.tile_format) + 1) }
|
||||
if app.tile_format == .end_ {
|
||||
|
@ -774,7 +774,7 @@ fn (mut app App) next_tile_format() {
|
|||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) undo() {
|
||||
if app.undo.len > 0 {
|
||||
undo := app.undo.pop()
|
||||
|
|
|
@ -75,7 +75,7 @@ fn (mut state BFState) find_matching_pairs() {
|
|||
}
|
||||
}
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
fn (state &BFState) panic_for_bracket(b1 rune, b2 rune) {
|
||||
panic('unbalanced `${b1}` found, its target `${b2}` is not known; address: ${state.address}, pc: ${state.pc}')
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ fn (mut state BFState) run() ? {
|
|||
}
|
||||
}
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
fn show_usage() {
|
||||
eprintln('you need to supply a brainfuck program/expression as a string argument,')
|
||||
eprintln('or filename.b, if it is located in a file (note the `.b` extension).')
|
||||
|
|
|
@ -2,12 +2,12 @@ module test_math
|
|||
|
||||
import math
|
||||
|
||||
[export: 'square']
|
||||
@[export: 'square']
|
||||
fn calculate_square(i int) int {
|
||||
return i * i
|
||||
}
|
||||
|
||||
[export: 'sqrt_of_sum_of_squares']
|
||||
@[export: 'sqrt_of_sum_of_squares']
|
||||
fn calculate_sqrt_of_sum_of_squares(x f64, y f64) f64 {
|
||||
return math.sqrt(x * x + y * y)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module test_print
|
||||
|
||||
[export: 'foo']
|
||||
@[export: 'foo']
|
||||
fn show_foo(s &char) {
|
||||
println(unsafe { cstring_to_vstring(s) })
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ module test
|
|||
|
||||
import math
|
||||
|
||||
[export: 'square']
|
||||
@[export: 'square']
|
||||
fn square(i int) int {
|
||||
return i * i
|
||||
}
|
||||
|
||||
[export: 'sqrt_of_sum_of_squares']
|
||||
@[export: 'sqrt_of_sum_of_squares']
|
||||
fn sqrt_of_sum_of_squares(x f64, y f64) f64 {
|
||||
return math.sqrt(x * x + y * y)
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ module test
|
|||
|
||||
import math
|
||||
|
||||
[export: 'square']
|
||||
@[export: 'square']
|
||||
fn square(i int) int {
|
||||
return i * i
|
||||
}
|
||||
|
||||
[export: 'sqrt_of_sum_of_squares']
|
||||
@[export: 'sqrt_of_sum_of_squares']
|
||||
fn sqrt_of_sum_of_squares(x f64, y f64) f64 {
|
||||
return math.sqrt(x * x + y * y)
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ fn on_frame(mut app App) {
|
|||
}
|
||||
|
||||
// Rotate a polygon round the centerpoint
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
fn draw_convex_poly_rotate(mut ctx gg.Context, dpi_scale f32, points []f32, c gx.Color, angle f32) {
|
||||
sa := math.sin(math.pi * angle / 180.0)
|
||||
ca := math.cos(math.pi * angle / 180.0)
|
||||
|
|
|
@ -13,7 +13,7 @@ fn my_print1() {
|
|||
}
|
||||
|
||||
// 2MB stack size
|
||||
[spawn_stack: 2097152]
|
||||
@[spawn_stack: 2097152]
|
||||
fn my_print2() {
|
||||
println('ahoj svet')
|
||||
}
|
||||
|
|
|
@ -35,30 +35,30 @@ const (
|
|||
pg_db = os.getenv_opt('PGDATABASE') or { 'test' }
|
||||
)
|
||||
|
||||
[table: 'modules']
|
||||
@[table: 'modules']
|
||||
struct Module {
|
||||
id int [primary; sql: serial]
|
||||
id int @[primary; sql: serial]
|
||||
name string
|
||||
nr_downloads int [sql: u64]
|
||||
nr_downloads int @[sql: u64]
|
||||
creator User
|
||||
}
|
||||
|
||||
struct User {
|
||||
id int [primary; sql: serial]
|
||||
age u32 [unique: 'user']
|
||||
name string [sql: 'username'; sql_type: 'VARCHAR(200)'; unique]
|
||||
is_customer bool [sql: 'abc'; unique: 'user']
|
||||
skipped_string string [skip]
|
||||
id int @[primary; sql: serial]
|
||||
age u32 @[unique: 'user']
|
||||
name string @[sql: 'username'; sql_type: 'VARCHAR(200)'; unique]
|
||||
is_customer bool @[sql: 'abc'; unique: 'user']
|
||||
skipped_string string @[skip]
|
||||
}
|
||||
|
||||
struct Parent {
|
||||
id int [primary; sql: serial]
|
||||
id int @[primary; sql: serial]
|
||||
name string
|
||||
children []Child [fkey: 'parent_id']
|
||||
children []Child @[fkey: 'parent_id']
|
||||
}
|
||||
|
||||
struct Child {
|
||||
id int [primary; sql: serial]
|
||||
id int @[primary; sql: serial]
|
||||
parent_id int
|
||||
name string
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ module library
|
|||
// (Normally, the exported name is a V mangled version based on the module
|
||||
// name followed by __, followed by the fn name, i.e. it would have been
|
||||
// `library__add_1`, if not for the export: tag).
|
||||
[export: 'add_1']
|
||||
@[export: 'add_1']
|
||||
pub fn add_1(x int, y int) int {
|
||||
return my_private_function(x + y)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ module library
|
|||
// (Normally, the exported name is a V mangled version based on the module
|
||||
// name followed by __, followed by the fn name, i.e. it would have been
|
||||
// `library__add_1`, if not for the export: tag).
|
||||
[export: 'add_1']
|
||||
@[export: 'add_1']
|
||||
pub fn add_1(x int, y int) int {
|
||||
return my_private_function(x + y)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ const (
|
|||
filled_color = gx.blue
|
||||
)
|
||||
|
||||
[live]
|
||||
@[live]
|
||||
fn print_automaton(app &App) {
|
||||
square_size := 18
|
||||
for y := 1; y < app.a.field.maxy; y++ {
|
||||
|
|
|
@ -17,7 +17,7 @@ fn new_a2d(maxx int, maxy int) &A2D {
|
|||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (a &A2D) set(x int, y int, newval int) {
|
||||
unsafe {
|
||||
mut e := &int(0)
|
||||
|
@ -26,7 +26,7 @@ pub fn (a &A2D) set(x int, y int, newval int) {
|
|||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (a &A2D) get(x int, y int) int {
|
||||
unsafe {
|
||||
mut e := &int(0)
|
||||
|
@ -36,7 +36,7 @@ pub fn (a &A2D) get(x int, y int) int {
|
|||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (a &A2D) clear() {
|
||||
for y := 0; y < a.maxy; y++ {
|
||||
for x := 0; x < a.maxx; x++ {
|
||||
|
|
|
@ -3,24 +3,24 @@ import rand
|
|||
import net.http
|
||||
|
||||
struct Weather {
|
||||
status string [skip] // drop this field
|
||||
api_version string [skip]
|
||||
api_status string [skip]
|
||||
lang string [skip]
|
||||
unit string [skip]
|
||||
tzshift int [skip]
|
||||
timezone string [skip]
|
||||
server_time u32 [skip]
|
||||
location []f32 [skip]
|
||||
status string @[skip] // drop this field
|
||||
api_version string @[skip]
|
||||
api_status string @[skip]
|
||||
lang string @[skip]
|
||||
unit string @[skip]
|
||||
tzshift int @[skip]
|
||||
timezone string @[skip]
|
||||
server_time u32 @[skip]
|
||||
location []f32 @[skip]
|
||||
result Result //[json: result] if the field name is different in JSON, it can be specified
|
||||
}
|
||||
|
||||
struct Result {
|
||||
realtime Realtime [skip]
|
||||
minutely Minutely [skip]
|
||||
hourly Hourly [skip]
|
||||
daily Daily [skip]
|
||||
primary int [skip]
|
||||
realtime Realtime @[skip]
|
||||
minutely Minutely @[skip]
|
||||
hourly Hourly @[skip]
|
||||
daily Daily @[skip]
|
||||
primary int @[skip]
|
||||
forecast_keypoint string
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import gg
|
|||
import gx
|
||||
import math
|
||||
|
||||
[heap]
|
||||
@[heap]
|
||||
pub struct Window {
|
||||
pub mut:
|
||||
ctx &gg.Context = unsafe { 0 }
|
||||
|
|
|
@ -91,7 +91,7 @@ fn (mut state AppState) update() {
|
|||
}
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn (mut state AppState) worker(id int, input chan MandelChunk, ready chan bool) {
|
||||
for {
|
||||
chunk := <-input or { break }
|
||||
|
|
|
@ -14,7 +14,7 @@ mut:
|
|||
pixels [pheight][pwidth]u32
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn (mut state AppState) update() {
|
||||
mut rcolor := u64(state.gg.frame)
|
||||
for {
|
||||
|
|
|
@ -51,7 +51,7 @@ fn main() {
|
|||
|
||||
// Try uncommenting or changing the lines inside the live functions.
|
||||
// Guess what will happen:
|
||||
[live]
|
||||
@[live]
|
||||
fn frame(mut game Game) {
|
||||
game.gg.begin()
|
||||
game.gg.draw_text_def(10, 5, 'Modify examples/hot_reload/bounce.v to get instant updates')
|
||||
|
@ -63,7 +63,7 @@ fn frame(mut game Game) {
|
|||
game.gg.end()
|
||||
}
|
||||
|
||||
[live]
|
||||
@[live]
|
||||
fn (mut game Game) update_model() {
|
||||
speed := 2
|
||||
game.x += speed * game.dx
|
||||
|
|
|
@ -39,7 +39,7 @@ fn frame(mut ctx Context) {
|
|||
ctx.gg.end()
|
||||
}
|
||||
|
||||
[live]
|
||||
@[live]
|
||||
fn (ctx &Context) draw() {
|
||||
s := gg.window_size()
|
||||
mut w := s.width
|
||||
|
|
|
@ -4,7 +4,7 @@ module main
|
|||
import time
|
||||
import v.live
|
||||
|
||||
[live]
|
||||
@[live]
|
||||
fn print_message() {
|
||||
info := live.info()
|
||||
println('OK reloads: ${info.reloads_ok:4d} | Total reloads: ${info.reloads:4d} | Hello! Modify this message while the program is running.')
|
||||
|
|
|
@ -8,10 +8,10 @@ import net.http
|
|||
import math
|
||||
import v.util.version
|
||||
|
||||
[table: 'benchmark']
|
||||
@[table: 'benchmark']
|
||||
struct Task {
|
||||
mut:
|
||||
id u32 [primary; serial; sql: serial]
|
||||
id u32 @[primary; serial; sql: serial]
|
||||
title string
|
||||
status string
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ fn new_app() &App {
|
|||
return app
|
||||
}
|
||||
|
||||
['/'; get]
|
||||
@['/'; get]
|
||||
pub fn (mut app App) controller_get_all_task() !vweb.Result {
|
||||
v_version := version.full_v_version(true)
|
||||
orm_stmt_kinds := ['insert', 'select', 'update']
|
||||
|
|
|
@ -8,7 +8,7 @@ struct App {
|
|||
vweb.Context
|
||||
}
|
||||
|
||||
[table: 'benchmark']
|
||||
@[table: 'benchmark']
|
||||
struct Task {
|
||||
mut:
|
||||
id u32 [primary; serial; sql: serial]
|
||||
|
@ -33,12 +33,12 @@ fn new_app() &App {
|
|||
return app
|
||||
}
|
||||
|
||||
['/hello-world']
|
||||
@['/hello-world']
|
||||
pub fn (mut app App) hello_world() vweb.Result {
|
||||
return app.text('hello world')
|
||||
}
|
||||
|
||||
['/sqlite-memory/:count']
|
||||
@['/sqlite-memory/:count']
|
||||
pub fn (mut app App) sqlite_memory(count int) vweb.Result {
|
||||
mut insert_stopwatchs := []int{}
|
||||
mut select_stopwatchs := []int{}
|
||||
|
@ -100,7 +100,7 @@ pub fn (mut app App) sqlite_memory(count int) vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/sqlite-file/:count']
|
||||
@['/sqlite-file/:count']
|
||||
pub fn (mut app App) sqlite_file(count int) vweb.Result {
|
||||
response := Response{
|
||||
insert: []
|
||||
|
@ -110,7 +110,7 @@ pub fn (mut app App) sqlite_file(count int) vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/postgres/:count']
|
||||
@['/postgres/:count']
|
||||
pub fn (mut app App) postgres(count int) vweb.Result {
|
||||
response := Response{
|
||||
insert: []
|
||||
|
@ -120,7 +120,7 @@ pub fn (mut app App) postgres(count int) vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/mysql/:count']
|
||||
@['/mysql/:count']
|
||||
pub fn (mut app App) mysql(count int) vweb.Result {
|
||||
response := Response{
|
||||
insert: []
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import log
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
fn should_not_return(mut logger log.Log) {
|
||||
logger.fatal('${@FILE_LINE}: yikes!')
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@ fn C.tray_app_run(&TrayInfo)
|
|||
fn C.tray_app_exit(&TrayInfo)
|
||||
|
||||
struct TrayMenuItem {
|
||||
id string [required] // Unique ID.
|
||||
text string [required] // Text to display.
|
||||
id string @[required] // Unique ID.
|
||||
text string @[required] // Text to display.
|
||||
}
|
||||
|
||||
// Parameters to configure the tray button.
|
||||
struct TrayParams {
|
||||
items []TrayMenuItem [required]
|
||||
items []TrayMenuItem @[required]
|
||||
on_click fn (item TrayMenuItem)
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ struct TrayInfo {
|
|||
app_delegate voidptr // pointer to AppDelegate
|
||||
}
|
||||
|
||||
[heap]
|
||||
@[heap]
|
||||
struct MyApp {
|
||||
mut:
|
||||
tray_info &TrayInfo = unsafe { nil }
|
||||
|
|
|
@ -44,37 +44,37 @@ mut:
|
|||
z f64 = 0.0
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (v Vec) + (b Vec) Vec {
|
||||
return Vec{v.x + b.x, v.y + b.y, v.z + b.z}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (v Vec) - (b Vec) Vec {
|
||||
return Vec{v.x - b.x, v.y - b.y, v.z - b.z}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (v Vec) * (b Vec) Vec {
|
||||
return Vec{v.x * b.x, v.y * b.y, v.z * b.z}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (v Vec) dot(b Vec) f64 {
|
||||
return v.x * b.x + v.y * b.y + v.z * b.z
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (v Vec) mult_s(b f64) Vec {
|
||||
return Vec{v.x * b, v.y * b, v.z * b}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (v Vec) cross(b Vec) Vec {
|
||||
return Vec{v.y * b.z - v.z * b.y, v.z * b.x - v.x * b.z, v.x * b.y - v.y * b.x}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (v Vec) norm() Vec {
|
||||
tmp_norm := 1.0 / math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
|
||||
return Vec{v.x * tmp_norm, v.y * tmp_norm, v.z * tmp_norm}
|
||||
|
@ -323,7 +323,7 @@ const (
|
|||
)
|
||||
|
||||
//********************************** Utilities ******************************
|
||||
[inline]
|
||||
@[inline]
|
||||
fn clamp(x f64) f64 {
|
||||
if x < 0 {
|
||||
return 0
|
||||
|
@ -334,7 +334,7 @@ fn clamp(x f64) f64 {
|
|||
return x
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn to_int(x f64) int {
|
||||
p := math.pow(clamp(x), 1.0 / 2.2)
|
||||
return int(p * 255.0 + 0.5)
|
||||
|
|
|
@ -9,7 +9,7 @@ import math
|
|||
// customisable through setting VJOBS
|
||||
const max_parallel_workers = runtime.nr_jobs()
|
||||
|
||||
[params]
|
||||
@[params]
|
||||
pub struct ParserSettings {
|
||||
sequential bool
|
||||
img bool
|
||||
|
@ -146,7 +146,7 @@ fn parse_parallel_args(extra_workers int) !ParallelArgs {
|
|||
return args
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn get_workers(workers int, extra_workers int) int {
|
||||
result := if workers + extra_workers <= args.max_parallel_workers {
|
||||
workers
|
||||
|
|
|
@ -4,7 +4,7 @@ import gx
|
|||
import os
|
||||
import sim
|
||||
|
||||
[params]
|
||||
@[params]
|
||||
pub struct ImageSettings {
|
||||
pub:
|
||||
width int = sim.default_width
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module sim
|
||||
|
||||
// log is a helper function to print debug info
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn log(info string) {
|
||||
$if verbose ? {
|
||||
println(info)
|
||||
|
|
|
@ -11,7 +11,7 @@ pub const (
|
|||
default_gravity = 4.9
|
||||
)
|
||||
|
||||
[params]
|
||||
@[params]
|
||||
pub struct SimParams {
|
||||
rope_length f64 = sim.default_rope_length
|
||||
bearing_mass f64 = sim.default_bearing_mass
|
||||
|
|
|
@ -14,7 +14,7 @@ pub const (
|
|||
default_height = 600
|
||||
)
|
||||
|
||||
[params]
|
||||
@[params]
|
||||
pub struct GridSettings {
|
||||
pub:
|
||||
width int = sim.default_width
|
||||
|
@ -27,7 +27,7 @@ pub fn new_grid_settings(settings GridSettings) GridSettings {
|
|||
}
|
||||
}
|
||||
|
||||
[params]
|
||||
@[params]
|
||||
pub struct RunnerSettings {
|
||||
pub:
|
||||
grid GridSettings
|
||||
|
|
|
@ -10,7 +10,7 @@ struct Message {
|
|||
message string
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn json_response() string {
|
||||
msg := Message{
|
||||
message: 'Hello, World!'
|
||||
|
@ -18,7 +18,7 @@ fn json_response() string {
|
|||
return json.encode(msg)
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn hello_response() string {
|
||||
return 'Hello, World!'
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ fn init_cube_glsl(mut app App) {
|
|||
println('GLSL init DONE!')
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn vec4(x f32, y f32, z f32, w f32) m4.Vec4 {
|
||||
return m4.Vec4{
|
||||
e: [x, y, z, w]!
|
||||
|
|
|
@ -358,7 +358,7 @@ fn init_cube_glsl_p(mut app App) {
|
|||
println('GLSL Puppy init DONE!')
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn vec4(x f32, y f32, z f32, w f32) m4.Vec4 {
|
||||
return m4.Vec4{
|
||||
e: [x, y, z, w]!
|
||||
|
|
|
@ -67,7 +67,7 @@ mut:
|
|||
/******************************************************************************
|
||||
* Draw functions
|
||||
******************************************************************************/
|
||||
[inline]
|
||||
@[inline]
|
||||
fn vec4(x f32, y f32, z f32, w f32) m4.Vec4 {
|
||||
return m4.Vec4{
|
||||
e: [x, y, z, w]!
|
||||
|
|
|
@ -60,7 +60,7 @@ fn graphics_frame(mut state AppState) {
|
|||
state.gg.end()
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut state AppState) bsample(idx int) u8 {
|
||||
return u8(127 + state.frames[(state.gframe + idx) & 2047] * 128)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ const (
|
|||
sw_start_ms = sw.elapsed().milliseconds()
|
||||
)
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn sintone(periods int, frame int, num_frames int) f32 {
|
||||
return math.sinf(f32(periods) * (2 * math.pi) * f32(frame) / f32(num_frames))
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ const (
|
|||
orange = ui.Color{255, 140, 0}
|
||||
)
|
||||
|
||||
[heap]
|
||||
@[heap]
|
||||
struct App {
|
||||
mut:
|
||||
tui &ui.Context = unsafe { nil }
|
||||
|
@ -239,7 +239,7 @@ fn (mut b Ball) update(dt f32) {
|
|||
b.pos.y += b.vel.y * b.acc.y * dt
|
||||
}
|
||||
|
||||
[heap]
|
||||
@[heap]
|
||||
struct Game {
|
||||
mut:
|
||||
app &App = unsafe { nil }
|
||||
|
|
|
@ -461,7 +461,7 @@ fn (mut app App) draw_footer() {
|
|||
// }
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) inc_size() {
|
||||
if app.size < 30 {
|
||||
app.size++
|
||||
|
@ -469,7 +469,7 @@ fn (mut app App) inc_size() {
|
|||
app.show_msg('inc. size: ${app.size}', 1)
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) dec_size() {
|
||||
if app.size > 1 {
|
||||
app.size--
|
||||
|
|
|
@ -256,7 +256,7 @@ fn (mut r Rat) randomize() {
|
|||
r.app.height - block_size - buffer)
|
||||
}
|
||||
|
||||
[heap]
|
||||
@[heap]
|
||||
struct App {
|
||||
mut:
|
||||
termui &termui.Context = unsafe { nil }
|
||||
|
|
|
@ -126,7 +126,7 @@ fn remap(v f32, min f32, max f32, new_min f32, new_max f32) f32 {
|
|||
return (((v - min) * (new_max - new_min)) / (max - min)) + new_min
|
||||
}
|
||||
|
||||
[if showfps ?]
|
||||
@[if showfps ?]
|
||||
fn (mut game Game) showfps() {
|
||||
game.frame++
|
||||
last_frame_ms := f64(game.frame_sw.elapsed().microseconds()) / 1000.0
|
||||
|
|
|
@ -127,7 +127,7 @@ fn remap(v f32, min f32, max f32, new_min f32, new_max f32) f32 {
|
|||
return (((v - min) * (new_max - new_min)) / (max - min)) + new_min
|
||||
}
|
||||
|
||||
[if showfps ?]
|
||||
@[if showfps ?]
|
||||
fn (mut game Game) showfps() {
|
||||
game.frame++
|
||||
last_frame_ms := f64(game.frame_sw.elapsed().microseconds()) / 1000.0
|
||||
|
|
|
@ -72,12 +72,12 @@ pub mut:
|
|||
* Utility functions
|
||||
*
|
||||
******************************************************************************/
|
||||
[inline]
|
||||
@[inline]
|
||||
fn modulo(x int, n int) int {
|
||||
return (x % n + n) % n
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn get_extension(x string) Item_type {
|
||||
// 4 char extension check
|
||||
if x.len > 4 {
|
||||
|
@ -110,7 +110,7 @@ fn get_extension(x string) Item_type {
|
|||
return .file
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn is_image(x Item_type) bool {
|
||||
if int(x) >= int(Item_type.bmp) {
|
||||
return true
|
||||
|
@ -118,7 +118,7 @@ fn is_image(x Item_type) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn is_container(x Item_type) bool {
|
||||
if x in [.zip, .folder] {
|
||||
return true
|
||||
|
@ -126,7 +126,7 @@ fn is_container(x Item_type) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (item_list Item_list) is_inside_a_container() bool {
|
||||
if item_list.lst.len <= 0 || item_list.n_item <= 0 {
|
||||
return false
|
||||
|
@ -134,7 +134,7 @@ fn (item_list Item_list) is_inside_a_container() bool {
|
|||
return item_list.lst[item_list.item_index].need_extract
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (item_list Item_list) get_file_path() string {
|
||||
if item_list.lst.len <= 0 || item_list.n_item <= 0 {
|
||||
return ''
|
||||
|
@ -334,7 +334,7 @@ fn (mut item_list Item_list) go_to_next_container(in_inc int) {
|
|||
* Other functions
|
||||
*
|
||||
******************************************************************************/
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut item_list Item_list) rotate(in_inc int) {
|
||||
item_list.lst[item_list.item_index].rotation += in_inc
|
||||
if item_list.lst[item_list.item_index].rotation >= 4 {
|
||||
|
|
|
@ -166,7 +166,7 @@ fn update_text_texture(sg_img gfx.Image, w int, h int, buf &u8) {
|
|||
* Memory buffer
|
||||
*
|
||||
******************************************************************************/
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut app App) resize_buf_if_needed(in_size int) {
|
||||
// manage the memory buffer
|
||||
if app.mem_buf_size < in_size {
|
||||
|
@ -191,7 +191,7 @@ fn (mut app App) resize_buf_if_needed(in_size int) {
|
|||
*
|
||||
******************************************************************************/
|
||||
// read_bytes from file in `path` in the memory buffer of app.
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
fn (mut app App) read_bytes(path string) bool {
|
||||
mut fp := os.vfopen(path, 'rb') or {
|
||||
eprintln('ERROR: Can not open the file [${path}].')
|
||||
|
@ -375,7 +375,7 @@ fn cleanup(mut app App) {
|
|||
* Draw functions
|
||||
*
|
||||
******************************************************************************/
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
fn frame(mut app App) {
|
||||
ws := gg.window_size_real_pixels()
|
||||
if ws.width <= 0 || ws.height <= 0 {
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn (mut app App) index() vweb.Result {
|
|||
return $vweb.html()
|
||||
}
|
||||
|
||||
['/upload'; post]
|
||||
@['/upload'; post]
|
||||
pub fn (mut app App) upload() vweb.Result {
|
||||
fdata := app.files['upfile']
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn (mut app App) index() vweb.Result {
|
|||
return $vweb.html()
|
||||
}
|
||||
|
||||
['/upload'; post]
|
||||
@['/upload'; post]
|
||||
pub fn (mut app App) upload() vweb.Result {
|
||||
dump(app.form)
|
||||
dump(app.files)
|
||||
|
@ -29,7 +29,7 @@ pub fn (mut app App) upload() vweb.Result {
|
|||
return $vweb.html()
|
||||
}
|
||||
|
||||
['/submit'; post]
|
||||
@['/submit'; post]
|
||||
pub fn (mut app App) submit() vweb.Result {
|
||||
dump(app.form)
|
||||
form_data := app.form.clone()
|
||||
|
|
|
@ -33,7 +33,7 @@ fn new_app() &App {
|
|||
return app
|
||||
}
|
||||
|
||||
['/']
|
||||
@['/']
|
||||
pub fn (mut app App) index() vweb.Result {
|
||||
println('Index page')
|
||||
title := 'Home Page'
|
||||
|
@ -43,8 +43,8 @@ pub fn (mut app App) index() vweb.Result {
|
|||
return app.html(base)
|
||||
}
|
||||
|
||||
[middleware: check_auth]
|
||||
['/admin/secrets']
|
||||
@[middleware: check_auth]
|
||||
@['/admin/secrets']
|
||||
pub fn (mut app App) secrets() vweb.Result {
|
||||
println('Secrets page')
|
||||
title := 'Secret Admin Page'
|
||||
|
@ -54,7 +54,7 @@ pub fn (mut app App) secrets() vweb.Result {
|
|||
return app.html(base)
|
||||
}
|
||||
|
||||
['/admin/:sub']
|
||||
@['/admin/:sub']
|
||||
pub fn (mut app App) dynamic(sub string) vweb.Result {
|
||||
println('Dynamic page')
|
||||
title := 'Secret dynamic'
|
||||
|
@ -64,7 +64,7 @@ pub fn (mut app App) dynamic(sub string) vweb.Result {
|
|||
return app.html(base)
|
||||
}
|
||||
|
||||
['/early']
|
||||
@['/early']
|
||||
pub fn (mut app App) early() vweb.Result {
|
||||
println('Early page')
|
||||
title := 'Early Exit'
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn (app &App) before_request() {
|
|||
}
|
||||
}
|
||||
|
||||
['/users/:user']
|
||||
@['/users/:user']
|
||||
pub fn (mut app App) user_endpoint(user string) vweb.Result {
|
||||
id := rand.intn(100) or { 0 }
|
||||
return app.json({
|
||||
|
@ -55,7 +55,7 @@ pub fn (mut app App) cookie() vweb.Result {
|
|||
return app.text('Response Headers\n${app.header}')
|
||||
}
|
||||
|
||||
[post]
|
||||
@[post]
|
||||
pub fn (mut app App) post() vweb.Result {
|
||||
return app.text('Post body: ${app.req.data}')
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ module main
|
|||
|
||||
import vweb
|
||||
|
||||
['/controller/auth'; post]
|
||||
@['/controller/auth'; post]
|
||||
pub fn (mut app App) controller_auth(username string, password string) vweb.Result {
|
||||
response := app.service_auth(username, password) or {
|
||||
app.set_status(400, '')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module main
|
||||
|
||||
struct AuthRequestDto {
|
||||
username string [nonull]
|
||||
password string [nonull]
|
||||
username string @[nonull]
|
||||
password string @[nonull]
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import vweb
|
|||
import encoding.base64
|
||||
import json
|
||||
|
||||
['/controller/products'; get]
|
||||
@['/controller/products'; get]
|
||||
pub fn (mut app App) controller_get_all_products() vweb.Result {
|
||||
token := app.req.header.get_custom('token') or { '' }
|
||||
|
||||
|
@ -30,7 +30,7 @@ pub fn (mut app App) controller_get_all_products() vweb.Result {
|
|||
// return app.text('response')
|
||||
}
|
||||
|
||||
['/controller/product/create'; post]
|
||||
@['/controller/product/create'; post]
|
||||
pub fn (mut app App) controller_create_product(product_name string) vweb.Result {
|
||||
if product_name == '' {
|
||||
app.set_status(400, '')
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
module main
|
||||
|
||||
[table: 'products']
|
||||
@[table: 'products']
|
||||
struct Product {
|
||||
id int [primary; sql: serial]
|
||||
id int @[primary; sql: serial]
|
||||
user_id int
|
||||
name string [sql_type: 'TEXT']
|
||||
created_at string [default: 'CURRENT_TIMESTAMP']
|
||||
name string @[sql_type: 'TEXT']
|
||||
created_at string @[default: 'CURRENT_TIMESTAMP']
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ module main
|
|||
|
||||
import vweb
|
||||
|
||||
['/products'; get]
|
||||
@['/products'; get]
|
||||
pub fn (mut app App) products() !vweb.Result {
|
||||
token := app.get_cookie('token') or {
|
||||
app.set_status(400, '')
|
||||
|
|
|
@ -4,7 +4,7 @@ import vweb
|
|||
import encoding.base64
|
||||
import json
|
||||
|
||||
['/controller/users'; get]
|
||||
@['/controller/users'; get]
|
||||
pub fn (mut app App) controller_get_all_user() vweb.Result {
|
||||
// token := app.get_cookie('token') or { '' }
|
||||
token := app.req.header.get_custom('token') or { '' }
|
||||
|
@ -21,7 +21,7 @@ pub fn (mut app App) controller_get_all_user() vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/controller/user'; get]
|
||||
@['/controller/user'; get]
|
||||
pub fn (mut app App) controller_get_user() vweb.Result {
|
||||
// token := app.get_cookie('token') or { '' }
|
||||
token := app.req.header.get_custom('token') or { '' }
|
||||
|
@ -47,7 +47,7 @@ pub fn (mut app App) controller_get_user() vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/controller/user/create'; post]
|
||||
@['/controller/user/create'; post]
|
||||
pub fn (mut app App) controller_create_user(username string, password string) vweb.Result {
|
||||
if username == '' {
|
||||
app.set_status(400, '')
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
module main
|
||||
|
||||
[table: 'users']
|
||||
@[table: 'users']
|
||||
pub struct User {
|
||||
mut:
|
||||
id int [primary; sql: serial]
|
||||
username string [sql_type: 'TEXT'; unique]
|
||||
password string [sql_type: 'TEXT']
|
||||
id int @[primary; sql: serial]
|
||||
username string @[sql_type: 'TEXT'; unique]
|
||||
password string @[sql_type: 'TEXT']
|
||||
active bool
|
||||
products []Product [fkey: 'user_id']
|
||||
products []Product @[fkey: 'user_id']
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ module main
|
|||
import vweb
|
||||
import json
|
||||
|
||||
['/auth/login'; post]
|
||||
@['/auth/login'; post]
|
||||
pub fn (mut app App) controller_auth() vweb.Result {
|
||||
body := json.decode(AuthRequestDto, app.req.data) or {
|
||||
app.set_status(400, '')
|
||||
|
|
|
@ -3,6 +3,6 @@ module main
|
|||
struct AuthRequestDto {
|
||||
// Adding a [required] attribute will make decoding fail, if that field is not present in the input.
|
||||
// If a field is not [required], but is missing, it will be assumed to have its default value, like 0 for numbers, or '' for strings, and decoding will not fail.
|
||||
username string [required]
|
||||
password string [required]
|
||||
username string @[required]
|
||||
password string @[required]
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ fn new_app() &App {
|
|||
return app
|
||||
}
|
||||
|
||||
['/'; get]
|
||||
@['/'; get]
|
||||
pub fn (mut app App) ping() ?vweb.Result {
|
||||
return app.text('ping')
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import vweb
|
|||
import json
|
||||
import databases
|
||||
|
||||
['/user/:id/get'; get]
|
||||
@['/user/:id/get'; get]
|
||||
pub fn (mut app App) controller_get_user_by_id(id int) vweb.Result {
|
||||
response := app.service_get_user_by_id(id) or {
|
||||
app.set_status(400, '')
|
||||
|
@ -13,7 +13,7 @@ pub fn (mut app App) controller_get_user_by_id(id int) vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/user/create'; post]
|
||||
@['/user/create'; post]
|
||||
pub fn (mut app App) controller_create_user() vweb.Result {
|
||||
body := json.decode(User, app.req.data) or {
|
||||
app.set_status(400, '')
|
||||
|
@ -28,7 +28,7 @@ pub fn (mut app App) controller_create_user() vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/user/get_all'; get]
|
||||
@['/user/get_all'; get]
|
||||
pub fn (mut app App) controller_get_all_user() vweb.Result {
|
||||
token := app.get_header('token')
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub fn (mut app App) controller_get_all_user() vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/user/get_by_username/:username'; get]
|
||||
@['/user/get_by_username/:username'; get]
|
||||
pub fn (mut app App) controller_get_by_username(username string) vweb.Result {
|
||||
response := app.service_get_by_username(username) or {
|
||||
app.set_status(400, '')
|
||||
|
@ -53,7 +53,7 @@ pub fn (mut app App) controller_get_by_username(username string) vweb.Result {
|
|||
return app.json(response)
|
||||
}
|
||||
|
||||
['/user/drop'; delete]
|
||||
@['/user/drop'; delete]
|
||||
pub fn (mut app App) delete() vweb.Result {
|
||||
mut db := databases.create_db_connection() or {
|
||||
app.set_status(400, '')
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
module main
|
||||
|
||||
[table: 'users']
|
||||
@[table: 'users']
|
||||
struct User {
|
||||
mut:
|
||||
id int [primary; sql: serial]
|
||||
username string [required; sql_type: 'TEXT']
|
||||
password string [required; sql_type: 'TEXT']
|
||||
created_at string [default: 'CURRENT_TIMESTAMP']
|
||||
updated_at string [default: 'CURRENT_TIMESTAMP']
|
||||
deleted_at string [default: 'CURRENT_TIMESTAMP']
|
||||
id int @[primary; sql: serial]
|
||||
username string @[required; sql_type: 'TEXT']
|
||||
password string @[required; sql_type: 'TEXT']
|
||||
created_at string @[default: 'CURRENT_TIMESTAMP']
|
||||
updated_at string @[default: 'CURRENT_TIMESTAMP']
|
||||
deleted_at string @[default: 'CURRENT_TIMESTAMP']
|
||||
active bool
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module main
|
||||
|
||||
struct Article {
|
||||
id int [primary; sql: serial]
|
||||
id int @[primary; sql: serial]
|
||||
title string
|
||||
text string
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn (app &App) index_html() vweb.Result {
|
|||
return $vweb.html()
|
||||
}
|
||||
*/
|
||||
['/index']
|
||||
@['/index']
|
||||
pub fn (app &App) index() vweb.Result {
|
||||
articles := app.find_all_articles()
|
||||
return $vweb.html()
|
||||
|
@ -43,12 +43,12 @@ pub fn (mut app App) before_request() {
|
|||
app.user_id = app.get_cookie('id') or { '0' }
|
||||
}
|
||||
|
||||
['/new']
|
||||
@['/new']
|
||||
pub fn (mut app App) new() vweb.Result {
|
||||
return $vweb.html()
|
||||
}
|
||||
|
||||
['/new_article'; post]
|
||||
@['/new_article'; post]
|
||||
pub fn (mut app App) new_article(title string, text string) vweb.Result {
|
||||
if title == '' || text == '' {
|
||||
return app.text('Empty text/title')
|
||||
|
@ -66,7 +66,7 @@ pub fn (mut app App) new_article(title string, text string) vweb.Result {
|
|||
return app.redirect('/')
|
||||
}
|
||||
|
||||
['/articles'; get]
|
||||
@['/articles'; get]
|
||||
pub fn (mut app App) articles() vweb.Result {
|
||||
articles := app.find_all_articles()
|
||||
json_result := json.encode(articles)
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn idx_max[T](array []T) !int {
|
|||
|
||||
// merge two sorted arrays (ascending) and maintain sorted order
|
||||
// Example: arrays.merge([1, 3, 5, 7], [2, 4, 6, 8]) // => [1, 2, 3, 4, 5, 6, 7, 8]
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
pub fn merge[T](a []T, b []T) []T {
|
||||
mut m := []T{len: a.len + b.len}
|
||||
mut ia := 0
|
||||
|
@ -522,7 +522,7 @@ pub fn rotate_right[T](mut array []T, k int) {
|
|||
}
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn ptr_rotate[T](left_ int, mid &T, right_ int) {
|
||||
sz := usize(sizeof(T))
|
||||
mut left := usize(left_)
|
||||
|
@ -597,7 +597,7 @@ fn raw_array_malloc_size[T]() isize {
|
|||
}
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn memswap(x voidptr, y voidptr, len usize) {
|
||||
block_size := isize(sizeof(Block))
|
||||
|
||||
|
@ -629,7 +629,7 @@ fn memswap(x voidptr, y voidptr, len usize) {
|
|||
}
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn swap_nonoverlapping[T](x_ &T, y_ &T, count int) {
|
||||
x := voidptr(x_)
|
||||
y := voidptr(y_)
|
||||
|
@ -672,7 +672,7 @@ fn can_copy_bits[T]() bool {
|
|||
|
||||
// carray_to_varray copies a C byte array into a V array of type `T`.
|
||||
// See also: `cstring_to_vstring`
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn carray_to_varray[T](c_array_data voidptr, items int) []T {
|
||||
mut v_array := []T{len: items}
|
||||
total_size := items * isize(sizeof(T))
|
||||
|
@ -713,7 +713,7 @@ pub fn find_last[T](array []T, predicate fn (elem T) bool) ?T {
|
|||
|
||||
// join_to_string takes in a custom transform function and joins all elements into a string with
|
||||
// the specified separator
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
pub fn join_to_string[T](array []T, separator string, transform fn (elem T) string) string {
|
||||
mut sb := strings.new_builder(array.len * 2)
|
||||
defer {
|
||||
|
|
|
@ -106,7 +106,7 @@ pub fn new(size int) BitField {
|
|||
}
|
||||
|
||||
// frees the memory allocated for the bitfield instance
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (instance &BitField) free() {
|
||||
unsafe {
|
||||
instance.field.free()
|
||||
|
@ -114,7 +114,7 @@ pub fn (instance &BitField) free() {
|
|||
}
|
||||
|
||||
// get_bit returns the value (0 or 1) of bit number 'bit_nr' (count from 0).
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (instance BitField) get_bit(bitnr int) int {
|
||||
if bitnr >= instance.size {
|
||||
return 0
|
||||
|
@ -123,7 +123,7 @@ pub fn (instance BitField) get_bit(bitnr int) int {
|
|||
}
|
||||
|
||||
// set_bit sets bit number 'bit_nr' to 1 (count from 0).
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (mut instance BitField) set_bit(bitnr int) {
|
||||
if bitnr >= instance.size {
|
||||
return
|
||||
|
@ -132,7 +132,7 @@ pub fn (mut instance BitField) set_bit(bitnr int) {
|
|||
}
|
||||
|
||||
// clear_bit clears (sets to zero) bit number 'bit_nr' (count from 0).
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (mut instance BitField) clear_bit(bitnr int) {
|
||||
if bitnr >= instance.size {
|
||||
return
|
||||
|
@ -226,7 +226,7 @@ pub fn (mut instance BitField) clear_all() {
|
|||
|
||||
// toggle_bit changes the value (from 0 to 1 or from 1 to 0) of bit
|
||||
// number 'bit_nr'.
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (mut instance BitField) toggle_bit(bitnr int) {
|
||||
if bitnr >= instance.size {
|
||||
return
|
||||
|
@ -328,7 +328,7 @@ pub fn join(input1 BitField, input2 BitField) BitField {
|
|||
}
|
||||
|
||||
// get_size returns the number of bits the array can hold.
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (instance BitField) get_size() int {
|
||||
return instance.size
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ pub fn (instance BitField) pop_count() int {
|
|||
}
|
||||
|
||||
// hamming computes the Hamming distance between two bit arrays.
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn hamming(input1 BitField, input2 BitField) int {
|
||||
input_xored := bf_xor(input1, input2)
|
||||
return input_xored.pop_count()
|
||||
|
@ -525,7 +525,7 @@ pub fn (instance BitField) rotate(offset int) BitField {
|
|||
|
||||
// Internal functions
|
||||
// clear_tail clears the extra bits that are not part of the bitfield, but yet are allocated
|
||||
[inline]
|
||||
@[inline]
|
||||
fn (mut instance BitField) clear_tail() {
|
||||
tail := instance.size % bitfield.slot_size
|
||||
if tail != 0 {
|
||||
|
@ -537,19 +537,19 @@ fn (mut instance BitField) clear_tail() {
|
|||
}
|
||||
|
||||
// bitmask is the bitmask needed to access a particular bit at offset bitnr
|
||||
[inline]
|
||||
@[inline]
|
||||
fn bitmask(bitnr int) u32 {
|
||||
return u32(u32(1) << u32(bitnr % bitfield.slot_size))
|
||||
}
|
||||
|
||||
// bitslot is the slot index (i.e. the integer) where a particular bit is located
|
||||
[inline]
|
||||
@[inline]
|
||||
fn bitslot(size int) int {
|
||||
return size / bitfield.slot_size
|
||||
}
|
||||
|
||||
// min returns the minimum of 2 integers; it is here to avoid importing math just for that
|
||||
[inline]
|
||||
@[inline]
|
||||
fn min(input1 int, input2 int) int {
|
||||
if input1 < input2 {
|
||||
return input1
|
||||
|
@ -559,7 +559,7 @@ fn min(input1 int, input2 int) int {
|
|||
}
|
||||
|
||||
// zbitnslots returns the minimum number of whole integers, needed to represent a bitfield of size length
|
||||
[inline]
|
||||
@[inline]
|
||||
fn zbitnslots(length int) int {
|
||||
return (length - 1) / bitfield.slot_size + 1
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ pub:
|
|||
element_size int // size in bytes of one element in the array.
|
||||
}
|
||||
|
||||
[flag]
|
||||
@[flag]
|
||||
pub enum ArrayFlags {
|
||||
noslices // when <<, `.noslices` will free the old data block immediately (you have to be sure, that there are *no slices* to that specific array). TODO: integrate with reference counting/compiler support for the static cases.
|
||||
noshrink // when `.noslices` and `.noshrink` are *both set*, .delete(x) will NOT allocate new memory and free the old. It will just move the elements in place, and adjust .len.
|
||||
|
@ -215,7 +215,7 @@ pub fn (a array) repeat(count int) array {
|
|||
// multi-dimensional arrays.
|
||||
//
|
||||
// It is `unsafe` to call directly because `depth` is not checked
|
||||
[direct_array_access; unsafe]
|
||||
@[direct_array_access; unsafe]
|
||||
pub fn (a array) repeat_to_depth(count int, depth int) array {
|
||||
if count < 0 {
|
||||
panic('array.repeat: count is negative: ${count}')
|
||||
|
@ -287,7 +287,7 @@ pub fn (mut a array) insert(i int, val voidptr) {
|
|||
|
||||
// insert_many is used internally to implement inserting many values
|
||||
// into an the array beginning at `i`.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut a array) insert_many(i int, val voidptr, size int) {
|
||||
$if !no_bounds_checking {
|
||||
if i < 0 || i > a.len {
|
||||
|
@ -313,7 +313,7 @@ pub fn (mut a array) prepend(val voidptr) {
|
|||
// prepend_many prepends another array to this array.
|
||||
// NOTE: `.prepend` is probably all you need.
|
||||
// NOTE: This code is never called in all of vlib
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut a array) prepend_many(val voidptr, size int) {
|
||||
unsafe { a.insert_many(0, val, size) }
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ pub fn (mut a array) clear() {
|
|||
// is not safe, when your array contains more complex elements,
|
||||
// like structs, maps, pointers etc, since setting them to 0,
|
||||
// can later lead to hard to find bugs.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (mut a array) reset() {
|
||||
unsafe { vmemset(a.data, 0, a.len * a.element_size) }
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ pub fn (mut a array) drop(num int) {
|
|||
}
|
||||
|
||||
// we manually inline this for single operations for performance without -prod
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
fn (a array) get_unsafe(i int) voidptr {
|
||||
unsafe {
|
||||
return &u8(a.data) + u64(i) * u64(a.element_size)
|
||||
|
@ -634,7 +634,7 @@ pub fn (a &array) clone() array {
|
|||
}
|
||||
|
||||
// recursively clone given array - `unsafe` when called directly because depth is not checked
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (a &array) clone_to_depth(depth int) array {
|
||||
mut arr := array{
|
||||
element_size: a.element_size
|
||||
|
@ -660,7 +660,7 @@ pub fn (a &array) clone_to_depth(depth int) array {
|
|||
}
|
||||
|
||||
// we manually inline this for single operations for performance without -prod
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
fn (mut a array) set_unsafe(i int, val voidptr) {
|
||||
unsafe { vmemcpy(&u8(a.data) + u64(a.element_size) * u64(i), val, a.element_size) }
|
||||
}
|
||||
|
@ -685,7 +685,7 @@ fn (mut a array) push(val voidptr) {
|
|||
|
||||
// push_many implements the functionality for pushing another array.
|
||||
// `val` is array.data and user facing usage is `a << [1,2,3]`
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (mut a3 array) push_many(val voidptr, size int) {
|
||||
if size <= 0 || val == unsafe { nil } {
|
||||
return
|
||||
|
@ -741,7 +741,7 @@ pub fn (a array) reverse() array {
|
|||
}
|
||||
|
||||
// free frees all memory occupied by the array.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (a &array) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
|
@ -894,7 +894,7 @@ pub fn (a array) contains(value voidptr) bool
|
|||
// or `-1` if the value is not found.
|
||||
pub fn (a array) index(value voidptr) int
|
||||
|
||||
[direct_array_access; unsafe]
|
||||
@[direct_array_access; unsafe]
|
||||
pub fn (mut a []string) free() {
|
||||
$if prealloc {
|
||||
return
|
||||
|
@ -910,7 +910,7 @@ pub fn (mut a []string) free() {
|
|||
|
||||
// str returns a string representation of an array of strings
|
||||
// Example: ['a', 'b', 'c'].str() // => "['a', 'b', 'c']".
|
||||
[direct_array_access; manualfree]
|
||||
@[direct_array_access; manualfree]
|
||||
pub fn (a []string) str() string {
|
||||
mut sb_len := 4 // 2x" + 1x, + 1xspace
|
||||
if a.len > 0 {
|
||||
|
@ -983,7 +983,7 @@ pub fn (mut a array) grow_cap(amount int) {
|
|||
// Internally, it does this by copying the entire array to
|
||||
// a new memory location (creating a clone) unless the array.cap
|
||||
// is already large enough.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (mut a array) grow_len(amount int) {
|
||||
a.ensure_cap(a.len + amount)
|
||||
a.len += amount
|
||||
|
@ -991,7 +991,7 @@ pub fn (mut a array) grow_len(amount int) {
|
|||
|
||||
// pointers returns a new array, where each element
|
||||
// is the address of the corresponding element in the array.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (a array) pointers() []voidptr {
|
||||
mut res := []voidptr{}
|
||||
for i in 0 .. a.len {
|
||||
|
@ -1002,7 +1002,7 @@ pub fn (a array) pointers() []voidptr {
|
|||
|
||||
// vbytes on`voidptr` makes a V []u8 structure from a C style memory buffer.
|
||||
// NOTE: the data is reused, NOT copied!
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (data voidptr) vbytes(len int) []u8 {
|
||||
res := array{
|
||||
element_size: 1
|
||||
|
@ -1015,7 +1015,7 @@ pub fn (data voidptr) vbytes(len int) []u8 {
|
|||
|
||||
// vbytes on `&u8` makes a V []u8 structure from a C style memory buffer.
|
||||
// NOTE: the data is reused, NOT copied!
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (data &u8) vbytes(len int) []u8 {
|
||||
return unsafe { voidptr(data).vbytes(len) }
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ fn (mut a array) ensure_cap_noscan(required int) {
|
|||
|
||||
// version of `repeat()` that handles multi dimensional arrays
|
||||
// `unsafe` to call directly because `depth` is not checked
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (a array) repeat_to_depth_noscan(count int, depth int) array {
|
||||
if count < 0 {
|
||||
panic('array.repeat: count is negative: ${count}')
|
||||
|
@ -165,7 +165,7 @@ fn (mut a array) insert_noscan(i int, val voidptr) {
|
|||
}
|
||||
|
||||
// insert_many inserts many values into the array from index `i`.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut a array) insert_many_noscan(i int, val voidptr, size int) {
|
||||
$if !no_bounds_checking {
|
||||
if i < 0 || i > a.len {
|
||||
|
@ -188,7 +188,7 @@ fn (mut a array) prepend_noscan(val voidptr) {
|
|||
}
|
||||
|
||||
// prepend_many prepends another array to this array.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut a array) prepend_many_noscan(val voidptr, size int) {
|
||||
unsafe { a.insert_many_noscan(0, val, size) }
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ fn (a array) clone_static_to_depth_noscan(depth int) array {
|
|||
}
|
||||
|
||||
// recursively clone given array - `unsafe` when called directly because depth is not checked
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (a &array) clone_to_depth_noscan(depth int) array {
|
||||
mut size := u64(a.cap) * u64(a.element_size)
|
||||
if size == 0 {
|
||||
|
@ -254,7 +254,7 @@ fn (mut a array) push_noscan(val voidptr) {
|
|||
|
||||
// push_many implements the functionality for pushing another array.
|
||||
// `val` is array.data and user facing usage is `a << [1,2,3]`
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut a3 array) push_many_noscan(val voidptr, size int) {
|
||||
if size <= 0 || val == unsafe { nil } {
|
||||
return
|
||||
|
@ -298,7 +298,7 @@ fn (mut a array) grow_cap_noscan(amount int) {
|
|||
}
|
||||
|
||||
// grow_len ensures that an array has a.len + amount of length
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
fn (mut a array) grow_len_noscan(amount int) {
|
||||
a.ensure_cap_noscan(a.len + amount)
|
||||
a.len += amount
|
||||
|
|
|
@ -982,7 +982,7 @@ fn test_in_struct() {
|
|||
assert baz.bar[0] == 3
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn test_direct_modification() {
|
||||
mut foo := [2, 0, 5]
|
||||
foo[1] = 3
|
||||
|
@ -1052,7 +1052,7 @@ fn test_trim() {
|
|||
assert arr.last() == 2
|
||||
}
|
||||
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
fn test_drop() {
|
||||
mut a := [1, 2]
|
||||
a << 3 // pushing assures reallocation; a.cap now should be bigger:
|
||||
|
@ -1246,7 +1246,7 @@ fn test_array_last() {
|
|||
assert s.last().val == 'a'
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn test_direct_array_access() {
|
||||
mut a := [11, 22, 33, 44]
|
||||
assert a[0] == 11
|
||||
|
@ -1259,7 +1259,7 @@ fn test_direct_array_access() {
|
|||
assert a == [21, 24, 14, 20]
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn test_direct_array_access_via_ptr() {
|
||||
mut b := [11, 22, 33, 44]
|
||||
unsafe {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[has_globals]
|
||||
@[has_globals]
|
||||
module builtin
|
||||
|
||||
type FnExitCb = fn ()
|
||||
|
@ -6,12 +6,12 @@ type FnExitCb = fn ()
|
|||
fn C.atexit(f FnExitCb) int
|
||||
fn C.strerror(int) &char
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
fn vhalt() {
|
||||
for {}
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn v_segmentation_fault_handler(signal_number int) {
|
||||
$if freestanding {
|
||||
eprintln('signal 11: segmentation fault')
|
||||
|
@ -27,7 +27,7 @@ fn v_segmentation_fault_handler(signal_number int) {
|
|||
}
|
||||
|
||||
// exit terminates execution immediately and returns exit `code` to the shell.
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn exit(code int) {
|
||||
C.exit(code)
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ pub fn exit(code int) {
|
|||
// recent versions of tcc print nicer backtraces automatically
|
||||
// Note: the duplication here is because tcc_backtrace should be called directly
|
||||
// inside the panic functions.
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
fn panic_debug(line_no int, file string, mod string, fn_name string, s string) {
|
||||
// Note: the order here is important for a stabler test output
|
||||
// module is less likely to change than function, etc...
|
||||
|
@ -83,21 +83,21 @@ fn panic_debug(line_no int, file string, mod string, fn_name string, s string) {
|
|||
|
||||
// panic_option_not_set is called by V, when you use option error propagation in your main function.
|
||||
// It ends the program with a panic.
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn panic_option_not_set(s string) {
|
||||
panic('option not set (${s})')
|
||||
}
|
||||
|
||||
// panic_result_not_set is called by V, when you use result error propagation in your main function
|
||||
// It ends the program with a panic.
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn panic_result_not_set(s string) {
|
||||
panic('result not set (${s})')
|
||||
}
|
||||
|
||||
// panic prints a nice error message, then exits the process with exit code of 1.
|
||||
// It also shows a backtrace on most platforms.
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn panic(s string) {
|
||||
$if freestanding {
|
||||
bare_panic(s)
|
||||
|
@ -153,7 +153,7 @@ pub fn c_error_number_str(errnum int) string {
|
|||
}
|
||||
|
||||
// panic with a C-API error message matching `errnum`
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn panic_error_number(basestr string, errnum int) {
|
||||
panic(basestr + c_error_number_str(errnum))
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ pub fn flush_stderr() {
|
|||
}
|
||||
|
||||
// print prints a message to stdout. Note that unlike `eprint`, stdout is not automatically flushed.
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
pub fn print(s string) {
|
||||
$if android && !termux {
|
||||
C.android_print(C.stdout, c'%.*s\n', s.len, s.str)
|
||||
|
@ -239,7 +239,7 @@ pub fn print(s string) {
|
|||
}
|
||||
|
||||
// println prints a message with a line end, to stdout. Note that unlike `eprintln`, stdout is not automatically flushed.
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
pub fn println(s string) {
|
||||
if s.str == 0 {
|
||||
println('println(NIL)')
|
||||
|
@ -260,7 +260,7 @@ pub fn println(s string) {
|
|||
}
|
||||
}
|
||||
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
fn _writeln_to_fd(fd int, s string) {
|
||||
$if !builtin_writeln_should_write_at_once ? {
|
||||
lf := u8(`\n`)
|
||||
|
@ -280,7 +280,7 @@ fn _writeln_to_fd(fd int, s string) {
|
|||
}
|
||||
}
|
||||
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
fn _write_buf_to_fd(fd int, buf &u8, buf_len int) {
|
||||
if buf_len <= 0 {
|
||||
return
|
||||
|
@ -315,7 +315,7 @@ __global total_m = i64(0)
|
|||
// malloc dynamically allocates a `n` bytes block of memory on the heap.
|
||||
// malloc returns a `byteptr` pointing to the memory address of the allocated space.
|
||||
// unlike the `calloc` family of functions - malloc will not zero the memory block.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn malloc(n isize) &u8 {
|
||||
$if trace_malloc ? {
|
||||
total_m += n
|
||||
|
@ -358,7 +358,7 @@ pub fn malloc(n isize) &u8 {
|
|||
return res
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn malloc_noscan(n isize) &u8 {
|
||||
$if trace_malloc ? {
|
||||
total_m += n
|
||||
|
@ -405,7 +405,7 @@ pub fn malloc_noscan(n isize) &u8 {
|
|||
return res
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn __at_least_one(how_many u64) u64 {
|
||||
// handle the case for allocating memory for empty structs, which have sizeof(EmptyStruct) == 0
|
||||
// in this case, just allocate a single byte, avoiding the panic for malloc(0)
|
||||
|
@ -417,7 +417,7 @@ fn __at_least_one(how_many u64) u64 {
|
|||
|
||||
// malloc_uncollectable dynamically allocates a `n` bytes block of memory
|
||||
// on the heap, which will NOT be garbage-collected (but its contents will).
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn malloc_uncollectable(n isize) &u8 {
|
||||
$if trace_malloc ? {
|
||||
total_m += n
|
||||
|
@ -462,7 +462,7 @@ pub fn malloc_uncollectable(n isize) &u8 {
|
|||
// The `b byteptr` must be a pointer to an existing memory block
|
||||
// previously allocated with `malloc`, `v_calloc` or `vcalloc`.
|
||||
// Please, see also realloc_data, and use it instead if possible.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn v_realloc(b &u8, n isize) &u8 {
|
||||
$if trace_realloc ? {
|
||||
C.fprintf(C.stderr, c'v_realloc %6d\n', n)
|
||||
|
@ -493,7 +493,7 @@ pub fn v_realloc(b &u8, n isize) &u8 {
|
|||
// instead of `v_realloc`, at least during development, because `realloc_data`
|
||||
// can make debugging easier, when you compile your program with
|
||||
// `-d debug_realloc`.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn realloc_data(old_data &u8, old_size int, new_size int) &u8 {
|
||||
$if trace_realloc ? {
|
||||
C.fprintf(C.stderr, c'realloc_data old_size: %6d new_size: %6d\n', old_size, new_size)
|
||||
|
@ -582,7 +582,7 @@ pub fn vcalloc_noscan(n isize) &u8 {
|
|||
}
|
||||
|
||||
// free allows for manually freeing memory allocated at the address `ptr`.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn free(ptr voidptr) {
|
||||
$if prealloc {
|
||||
return
|
||||
|
@ -604,7 +604,7 @@ pub fn free(ptr voidptr) {
|
|||
// memdup then copies the contents of `src` into the allocated space and
|
||||
// returns a pointer to the newly allocated space.
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn memdup(src voidptr, sz isize) voidptr {
|
||||
$if trace_memdup ? {
|
||||
C.fprintf(C.stderr, c'memdup size: %10d\n', sz)
|
||||
|
@ -618,7 +618,7 @@ pub fn memdup(src voidptr, sz isize) voidptr {
|
|||
}
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn memdup_noscan(src voidptr, sz isize) voidptr {
|
||||
$if trace_memdup ? {
|
||||
C.fprintf(C.stderr, c'memdup_noscan size: %10d\n', sz)
|
||||
|
@ -636,7 +636,7 @@ pub fn memdup_noscan(src voidptr, sz isize) voidptr {
|
|||
// on the heap, which will NOT be garbage-collected (but its contents will).
|
||||
// memdup_uncollectable then copies the contents of `src` into the allocated
|
||||
// space and returns a pointer to the newly allocated space.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn memdup_uncollectable(src voidptr, sz isize) voidptr {
|
||||
$if trace_memdup ? {
|
||||
C.fprintf(C.stderr, c'memdup_uncollectable size: %10d\n', sz)
|
||||
|
@ -680,7 +680,7 @@ pub fn gc_memory_use() usize {
|
|||
}
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
fn v_fixed_index(i int, len int) int {
|
||||
$if !no_bounds_checking {
|
||||
if i < 0 || i >= len {
|
||||
|
@ -695,8 +695,8 @@ fn v_fixed_index(i int, len int) int {
|
|||
// They are used internally by V's builtin; for user code, it is much
|
||||
// more convenient to just use `os.args` instead.
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
__global g_main_argc = int(0)
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
__global g_main_argv = unsafe { nil }
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
[has_globals]
|
||||
@[has_globals]
|
||||
module builtin
|
||||
|
||||
// isnil returns true if an object is nil (only for C objects).
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn isnil(v voidptr) bool {
|
||||
return v == 0
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ pub:
|
|||
|
||||
// free frees the memory occupied by the assertion meta data. It is called automatically by
|
||||
// the code, that V's test framework generates, after all other callbacks have been called.
|
||||
[manualfree; unsafe]
|
||||
@[manualfree; unsafe]
|
||||
pub fn (ami &VAssertMetaInfo) free() {
|
||||
unsafe {
|
||||
ami.fpath.free()
|
||||
|
|
|
@ -2,19 +2,19 @@ module builtin
|
|||
|
||||
// These are just dummy implementations to appease linking on musl/alpine
|
||||
|
||||
[export: 'backtrace_symbols']
|
||||
[weak]
|
||||
@[export: 'backtrace_symbols']
|
||||
@[weak]
|
||||
fn vbacktrace_symbols(const_buffer &voidptr, size int) &&char {
|
||||
return 0
|
||||
}
|
||||
|
||||
[export: 'backtrace']
|
||||
[weak]
|
||||
@[export: 'backtrace']
|
||||
@[weak]
|
||||
fn vbacktrace(buffer &voidptr, size int) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
[export: 'backtrace_symbols_fd']
|
||||
[weak]
|
||||
@[export: 'backtrace_symbols_fd']
|
||||
@[weak]
|
||||
fn vbacktrace_symbols_fd(const_buffer &voidptr, size int, fd int) {
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[has_globals]
|
||||
@[has_globals]
|
||||
module builtin
|
||||
|
||||
#flag -I@VEXEROOT/thirdparty/libbacktrace
|
||||
|
@ -85,7 +85,7 @@ fn bt_error_handler(data voidptr, msg &char, errnum int) {
|
|||
exit(1)
|
||||
}
|
||||
|
||||
[noinline]
|
||||
@[noinline]
|
||||
fn print_libbacktrace(frames_to_skip int) {
|
||||
$if no_backtrace ? {
|
||||
return
|
||||
|
@ -94,7 +94,7 @@ fn print_libbacktrace(frames_to_skip int) {
|
|||
C.backtrace_full(bt_state, frames_to_skip, bt_print_callback, bt_error_callback, data)
|
||||
}
|
||||
|
||||
[noinline]
|
||||
@[noinline]
|
||||
fn eprint_libbacktrace(frames_to_skip int) {
|
||||
$if no_backtrace ? {
|
||||
return
|
||||
|
|
|
@ -14,7 +14,7 @@ fn break_if_debugger_attached() {
|
|||
}
|
||||
}
|
||||
|
||||
[markused; noreturn]
|
||||
@[markused; noreturn]
|
||||
pub fn panic_lasterr(base string) {
|
||||
// TODO: use strerror_r and errno
|
||||
panic(base + ' unknown')
|
||||
|
|
|
@ -3,6 +3,6 @@ module builtin
|
|||
fn print_libbacktrace(frames_to_skip int) {
|
||||
}
|
||||
|
||||
[noinline]
|
||||
@[noinline]
|
||||
fn eprint_libbacktrace(frames_to_skip int) {
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ fn test_g_main_argv() {
|
|||
assert first_arg.contains('builtin_test')
|
||||
}
|
||||
|
||||
[if windows]
|
||||
@[if windows]
|
||||
fn test_bool_size() {
|
||||
println(@LOCATION)
|
||||
assert sizeof(C.BOOL) == 4
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
[has_globals]
|
||||
@[has_globals]
|
||||
module builtin
|
||||
|
||||
// g_original_codepage - used to restore the original windows console code page when exiting
|
||||
|
@ -97,7 +97,7 @@ fn add_vectored_exception_handler(handler VectoredExceptionHandler) {
|
|||
C.AddVectoredExceptionHandler(1, voidptr(handler))
|
||||
}
|
||||
|
||||
[callconv: stdcall]
|
||||
@[callconv: stdcall]
|
||||
fn unhandled_exception_handler(e &ExceptionPointers) int {
|
||||
match e.exception_record.code {
|
||||
// These are 'used' by the backtrace printer
|
||||
|
@ -164,7 +164,7 @@ pub fn winapi_lasterr_str() string {
|
|||
}
|
||||
|
||||
// panic with an error message generated from WinAPI's `LastError`
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn panic_lasterr(base string) {
|
||||
panic(base + winapi_lasterr_str())
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module builtin
|
||||
|
||||
[typedef]
|
||||
@[typedef]
|
||||
pub struct C.FILE {}
|
||||
|
||||
// <string.h>
|
||||
|
@ -12,7 +12,7 @@ fn C.memmove(dest voidptr, const_src voidptr, n usize) voidptr
|
|||
|
||||
fn C.memset(str voidptr, c int, n usize) voidptr
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.calloc(int, int) &u8
|
||||
|
||||
fn C.atoi(&char) int
|
||||
|
@ -23,7 +23,7 @@ fn C.realloc(a &u8, b int) &u8
|
|||
|
||||
fn C.free(ptr voidptr)
|
||||
|
||||
[noreturn; trusted]
|
||||
@[noreturn; trusted]
|
||||
fn C.exit(code int)
|
||||
|
||||
fn C.qsort(base voidptr, items usize, item_size usize, cb C.qsort_callback_func)
|
||||
|
@ -34,7 +34,7 @@ fn C.strlen(s &char) int
|
|||
|
||||
fn C.sscanf(&u8, &u8, ...&u8) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.isdigit(c int) bool
|
||||
|
||||
// stdio.h
|
||||
|
@ -78,7 +78,7 @@ fn C.strrchr(s &char, c int) &char
|
|||
fn C.strchr(s &char, c int) &char
|
||||
|
||||
// process execution, os.process:
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.getpid() int
|
||||
|
||||
fn C.getuid() int
|
||||
|
@ -101,14 +101,14 @@ fn C._execvp(cmd_path &char, args &&char) int
|
|||
|
||||
fn C.strcmp(s1 &char, s2 &char) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.fork() int
|
||||
|
||||
fn C.wait(status &int) int
|
||||
|
||||
fn C.waitpid(pid int, status &int, options int) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.kill(pid int, sig int) int
|
||||
|
||||
fn C.setenv(&char, &char, int) int
|
||||
|
@ -135,24 +135,24 @@ fn C.rename(old_filename &char, new_filename &char) int
|
|||
|
||||
fn C.fgets(str &char, n int, stream &C.FILE) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.sigemptyset() int
|
||||
|
||||
fn C.getcwd(buf &char, size usize) &char
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.mktime() int
|
||||
|
||||
fn C.gettimeofday(tv &C.timeval, tz &C.timezone) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.sleep(seconds u32) u32
|
||||
|
||||
// fn C.usleep(usec useconds_t) int
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.usleep(usec u32) int
|
||||
|
||||
[typedef]
|
||||
@[typedef]
|
||||
pub struct C.DIR {
|
||||
}
|
||||
|
||||
|
@ -164,30 +164,30 @@ fn C.closedir(dirp &C.DIR) int
|
|||
fn C.mkdir(path &char, mode u32) int
|
||||
|
||||
// C.rand returns a pseudorandom integer from 0 (inclusive) to C.RAND_MAX (exclusive)
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.rand() int
|
||||
|
||||
// C.srand seeds the internal PRNG with the given value.
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.srand(seed u32)
|
||||
|
||||
fn C.atof(str &char) f64
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.tolower(c int) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.toupper(c int) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.isspace(c int) int
|
||||
|
||||
fn C.strchr(s &char, c int) &char
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.getchar() int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.putchar(int) int
|
||||
|
||||
fn C.strdup(s &char) &char
|
||||
|
@ -198,33 +198,33 @@ fn C.strcasecmp(s &char, s2 &char) int
|
|||
|
||||
fn C.strncmp(s &char, s2 &char, n int) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.strerror(int) &char
|
||||
|
||||
fn C.snprintf(str &char, size usize, format &char, opt ...voidptr) int
|
||||
|
||||
fn C.fprintf(voidptr, &char, ...voidptr)
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.WIFEXITED(status int) bool
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.WEXITSTATUS(status int) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.WIFSIGNALED(status int) bool
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.WTERMSIG(status int) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.isatty(fd int) int
|
||||
|
||||
fn C.syscall(number int, va ...voidptr) int
|
||||
|
||||
fn C.sysctl(name &int, namelen u32, oldp voidptr, oldlenp voidptr, newp voidptr, newlen usize) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C._fileno(int) int
|
||||
|
||||
type C.intptr_t = voidptr
|
||||
|
@ -251,7 +251,7 @@ fn C.GetComputerNameW(&u16, &u32) bool
|
|||
|
||||
fn C.GetUserNameW(&u16, &u32) bool
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.SendMessageTimeout() isize
|
||||
|
||||
fn C.SendMessageTimeoutW(hWnd voidptr, msg u32, wParam &u16, lParam &u32, fuFlags u32, uTimeout u32, lpdwResult &u64) isize
|
||||
|
@ -286,7 +286,7 @@ fn C.SetConsoleMode(voidptr, u32) bool
|
|||
|
||||
fn C.GetConsoleMode(voidptr, &u32) bool
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.GetCurrentProcessId() u32
|
||||
|
||||
fn C.wprintf()
|
||||
|
@ -336,7 +336,7 @@ fn C._fullpath() int
|
|||
|
||||
fn C.GetFullPathName(voidptr, u32, voidptr, voidptr) u32
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.GetCommandLine() voidptr
|
||||
|
||||
fn C.LocalFree()
|
||||
|
@ -358,15 +358,15 @@ fn C.CloseHandle(voidptr) int
|
|||
|
||||
fn C.GetExitCodeProcess(hProcess voidptr, lpExitCode &u32)
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.GetTickCount() i64
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.Sleep(dwMilliseconds u32)
|
||||
|
||||
fn C.WSAStartup(u16, &voidptr) int
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.WSAGetLastError() int
|
||||
|
||||
fn C.closesocket(int) int
|
||||
|
@ -379,7 +379,7 @@ fn C.vschannel_cleanup(&C.TlsContext)
|
|||
|
||||
fn C.URLDownloadToFile(int, &u16, &u16, int, int)
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.GetLastError() u32
|
||||
|
||||
fn C.CreateDirectory(&u8, int) bool
|
||||
|
@ -464,14 +464,14 @@ fn C.sem_timedwait(voidptr, voidptr) int
|
|||
fn C.sem_destroy(voidptr) int
|
||||
|
||||
// MacOS semaphore functions
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.dispatch_semaphore_create(i64) voidptr
|
||||
|
||||
fn C.dispatch_semaphore_signal(voidptr) i64
|
||||
|
||||
fn C.dispatch_semaphore_wait(voidptr, u64) i64
|
||||
|
||||
[trusted]
|
||||
@[trusted]
|
||||
fn C.dispatch_time(u64, i64) u64
|
||||
|
||||
fn C.dispatch_release(voidptr)
|
||||
|
|
|
@ -2,14 +2,14 @@ module builtin
|
|||
|
||||
// vstrlen returns the V length of the C string `s` (0 terminator is not counted).
|
||||
// The C string is expected to be a &byte pointer.
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
pub fn vstrlen(s &u8) int {
|
||||
return unsafe { C.strlen(&char(s)) }
|
||||
}
|
||||
|
||||
// vstrlen_char returns the V length of the C string `s` (0 terminator is not counted).
|
||||
// The C string is expected to be a &char pointer.
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
pub fn vstrlen_char(s &char) int {
|
||||
return unsafe { C.strlen(s) }
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub fn vstrlen_char(s &char) int {
|
|||
// vmemcpy copies n bytes from memory area src to memory area dest.
|
||||
// The memory areas *MUST NOT OVERLAP*. Use vmemmove, if the memory
|
||||
// areas do overlap. vmemcpy returns a pointer to `dest`.
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
pub fn vmemcpy(dest voidptr, const_src voidptr, n isize) voidptr {
|
||||
$if trace_vmemcpy ? {
|
||||
C.fprintf(C.stderr, c'vmemcpy dest: %p src: %p n: %6ld\n', dest, const_src, n)
|
||||
|
@ -32,7 +32,7 @@ pub fn vmemcpy(dest voidptr, const_src voidptr, n isize) voidptr {
|
|||
// in `src` are first copied into a temporary array that does not overlap
|
||||
// `src` or `dest`, and the bytes are then copied from the temporary array
|
||||
// to `dest`. vmemmove returns a pointer to `dest`.
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
pub fn vmemmove(dest voidptr, const_src voidptr, n isize) voidptr {
|
||||
$if trace_vmemmove ? {
|
||||
C.fprintf(C.stderr, c'vmemmove dest: %p src: %p n: %6ld\n', dest, const_src, n)
|
||||
|
@ -54,7 +54,7 @@ pub fn vmemmove(dest voidptr, const_src voidptr, n isize) voidptr {
|
|||
// secrets, because the required CPU time depends on the number of equal bytes.
|
||||
// You should use a function that performs comparisons in constant time for
|
||||
// this.
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
pub fn vmemcmp(const_s1 voidptr, const_s2 voidptr, n isize) int {
|
||||
$if trace_vmemcmp ? {
|
||||
C.fprintf(C.stderr, c'vmemcmp s1: %p s2: %p n: %6ld\n', const_s1, const_s2, n)
|
||||
|
@ -66,7 +66,7 @@ pub fn vmemcmp(const_s1 voidptr, const_s2 voidptr, n isize) int {
|
|||
|
||||
// vmemset fills the first `n` bytes of the memory area pointed to by `s`,
|
||||
// with the constant byte `c`. It returns a pointer to the memory area `s`.
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
pub fn vmemset(s voidptr, c int, n isize) voidptr {
|
||||
$if trace_vmemset ? {
|
||||
C.fprintf(C.stderr, c'vmemset s: %p c: %d n: %6ld\n', s, c, n)
|
||||
|
@ -78,7 +78,7 @@ pub fn vmemset(s voidptr, c int, n isize) voidptr {
|
|||
|
||||
type FnSortCB = fn (const_a voidptr, const_b voidptr) int
|
||||
|
||||
[inline; unsafe]
|
||||
@[inline; unsafe]
|
||||
fn vqsort(base voidptr, nmemb usize, size usize, sort_cb FnSortCB) {
|
||||
C.qsort(base, nmemb, size, voidptr(sort_cb))
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ $if !native {
|
|||
----- f64 to string functions -----
|
||||
*/
|
||||
// str return a `f64` as `string` in suitable notation.
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (x f64) str() string {
|
||||
unsafe {
|
||||
f := strconv.Float64u{
|
||||
|
@ -37,7 +37,7 @@ pub fn (x f64) str() string {
|
|||
}
|
||||
|
||||
// strg return a `f64` as `string` in "g" printf format
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (x f64) strg() string {
|
||||
if x == 0 {
|
||||
return '0.0'
|
||||
|
@ -51,14 +51,14 @@ pub fn (x f64) strg() string {
|
|||
}
|
||||
|
||||
// str returns the value of the `float_literal` as a `string`.
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (d float_literal) str() string {
|
||||
return f64(d).str()
|
||||
}
|
||||
|
||||
// strsci returns the `f64` as a `string` in scientific notation with `digit_num` decimals displayed, max 17 digits.
|
||||
// Example: assert f64(1.234).strsci(3) == '1.234e+00'
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (x f64) strsci(digit_num int) string {
|
||||
mut n_digit := digit_num
|
||||
if n_digit < 1 {
|
||||
|
@ -71,7 +71,7 @@ pub fn (x f64) strsci(digit_num int) string {
|
|||
|
||||
// strlong returns a decimal notation of the `f64` as a `string`.
|
||||
// Example: assert f64(1.23456).strlong() == '1.23456'
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (x f64) strlong() string {
|
||||
return strconv.f64_to_str_l(x)
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ pub fn (x f64) strlong() string {
|
|||
----- f32 to string functions -----
|
||||
*/
|
||||
// str returns a `f32` as `string` in suitable notation.
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (x f32) str() string {
|
||||
unsafe {
|
||||
f := strconv.Float32u{
|
||||
|
@ -103,7 +103,7 @@ pub fn (x f32) str() string {
|
|||
}
|
||||
|
||||
// strg return a `f32` as `string` in "g" printf format
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (x f32) strg() string {
|
||||
if x == 0 {
|
||||
return '0.0'
|
||||
|
@ -118,7 +118,7 @@ pub fn (x f32) strg() string {
|
|||
|
||||
// strsci returns the `f32` as a `string` in scientific notation with `digit_num` decimals displayed, max 8 digits.
|
||||
// Example: assert f32(1.234).strsci(3) == '1.234e+00'
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (x f32) strsci(digit_num int) string {
|
||||
mut n_digit := digit_num
|
||||
if n_digit < 1 {
|
||||
|
@ -130,7 +130,7 @@ pub fn (x f32) strsci(digit_num int) string {
|
|||
}
|
||||
|
||||
// strlong returns a decimal notation of the `f32` as a `string`.
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (x f32) strlong() string {
|
||||
return strconv.f32_to_str_l(x)
|
||||
}
|
||||
|
@ -141,42 +141,42 @@ pub fn (x f32) strlong() string {
|
|||
*/
|
||||
// f32_abs returns the absolute value of `a` as a `f32` value.
|
||||
// Example: assert f32_abs(-2.0) == 2.0
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn f32_abs(a f32) f32 {
|
||||
return if a < 0 { -a } else { a }
|
||||
}
|
||||
|
||||
// f64_abs returns the absolute value of `a` as a `f64` value.
|
||||
// Example: assert f64_abs(-2.0) == f64(2.0)
|
||||
[inline]
|
||||
@[inline]
|
||||
fn f64_abs(a f64) f64 {
|
||||
return if a < 0 { -a } else { a }
|
||||
}
|
||||
|
||||
// f32_max returns the largest `f32` of input `a` and `b`.
|
||||
// Example: assert f32_max(2.0,3.0) == 3.0
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn f32_max(a f32, b f32) f32 {
|
||||
return if a > b { a } else { b }
|
||||
}
|
||||
|
||||
// f32_min returns the smallest `f32` of input `a` and `b`.
|
||||
// Example: assert f32_min(2.0,3.0) == 2.0
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn f32_min(a f32, b f32) f32 {
|
||||
return if a < b { a } else { b }
|
||||
}
|
||||
|
||||
// f64_max returns the largest `f64` of input `a` and `b`.
|
||||
// Example: assert f64_max(2.0,3.0) == 3.0
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn f64_max(a f64, b f64) f64 {
|
||||
return if a > b { a } else { b }
|
||||
}
|
||||
|
||||
// f64_min returns the smallest `f64` of input `a` and `b`.
|
||||
// Example: assert f64_min(2.0,3.0) == 2.0
|
||||
[inline]
|
||||
@[inline]
|
||||
fn f64_min(a f64, b f64) f64 {
|
||||
return if a < b { a } else { b }
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ fn f64_min(a f64, b f64) f64 {
|
|||
// eq_epsilon returns true if the `f32` is equal to input `b`.
|
||||
// using an epsilon of typically 1E-5 or higher (backend/compiler dependent).
|
||||
// Example: assert f32(2.0).eq_epsilon(2.0)
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (a f32) eq_epsilon(b f32) bool {
|
||||
hi := f32_max(f32_abs(a), f32_abs(b))
|
||||
delta := f32_abs(a - b)
|
||||
|
@ -206,7 +206,7 @@ pub fn (a f32) eq_epsilon(b f32) bool {
|
|||
// eq_epsilon returns true if the `f64` is equal to input `b`.
|
||||
// using an epsilon of typically 1E-9 or higher (backend/compiler dependent).
|
||||
// Example: assert f64(2.0).eq_epsilon(2.0)
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (a f64) eq_epsilon(b f64) bool {
|
||||
hi := f64_max(f64_abs(a), f64_abs(b))
|
||||
delta := f64_abs(a - b)
|
||||
|
|
|
@ -76,7 +76,7 @@ pub const (
|
|||
|
||||
// This implementation is the quickest with gcc -O2
|
||||
// str_l returns the string representation of the integer nn with max chars.
|
||||
[direct_array_access; inline]
|
||||
@[direct_array_access; inline]
|
||||
fn (nn int) str_l(max int) string {
|
||||
unsafe {
|
||||
mut n := i64(nn)
|
||||
|
@ -175,7 +175,7 @@ pub fn (n int) str() string {
|
|||
|
||||
// str returns the value of the `u32` as a `string`.
|
||||
// Example: assert u32(20000).str() == '20000'
|
||||
[direct_array_access; inline]
|
||||
@[direct_array_access; inline]
|
||||
pub fn (nn u32) str() string {
|
||||
unsafe {
|
||||
mut n := nn
|
||||
|
@ -212,14 +212,14 @@ pub fn (nn u32) str() string {
|
|||
}
|
||||
|
||||
// str returns the value of the `int_literal` as a `string`.
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (n int_literal) str() string {
|
||||
return i64(n).str()
|
||||
}
|
||||
|
||||
// str returns the value of the `i64` as a `string`.
|
||||
// Example: assert i64(-200000).str() == '-200000'
|
||||
[direct_array_access; inline]
|
||||
@[direct_array_access; inline]
|
||||
pub fn (nn i64) str() string {
|
||||
unsafe {
|
||||
mut n := nn
|
||||
|
@ -268,7 +268,7 @@ pub fn (nn i64) str() string {
|
|||
|
||||
// str returns the value of the `u64` as a `string`.
|
||||
// Example: assert u64(2000000).str() == '2000000'
|
||||
[direct_array_access; inline]
|
||||
@[direct_array_access; inline]
|
||||
pub fn (nn u64) str() string {
|
||||
unsafe {
|
||||
mut n := nn
|
||||
|
@ -317,7 +317,7 @@ pub fn (b bool) str() string {
|
|||
//
|
||||
|
||||
// u64_to_hex converts the number `nn` to a (zero padded if necessary) hexadecimal `string`.
|
||||
[direct_array_access; inline]
|
||||
@[direct_array_access; inline]
|
||||
fn u64_to_hex(nn u64, len u8) string {
|
||||
mut n := nn
|
||||
mut buf := [17]u8{}
|
||||
|
@ -332,7 +332,7 @@ fn u64_to_hex(nn u64, len u8) string {
|
|||
}
|
||||
|
||||
// u64_to_hex_no_leading_zeros converts the number `nn` to hexadecimal `string`.
|
||||
[direct_array_access; inline]
|
||||
@[direct_array_access; inline]
|
||||
fn u64_to_hex_no_leading_zeros(nn u64, len u8) string {
|
||||
mut n := nn
|
||||
mut buf := [17]u8{}
|
||||
|
@ -527,7 +527,7 @@ pub fn (b u8) ascii_str() string {
|
|||
|
||||
// str_escaped returns the contents of `byte` as an escaped `string`.
|
||||
// Example: assert u8(0).str_escaped() == r'`\0`'
|
||||
[manualfree]
|
||||
@[manualfree]
|
||||
pub fn (b u8) str_escaped() string {
|
||||
str := match b {
|
||||
0 {
|
||||
|
@ -573,7 +573,7 @@ pub fn (b u8) str_escaped() string {
|
|||
// is_capital returns `true`, if the byte is a Latin capital letter.
|
||||
// Example: assert `H`.is_capital() == true
|
||||
// Example: assert `h`.is_capital() == false
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (c u8) is_capital() bool {
|
||||
return c >= `A` && c <= `Z`
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ pub fn (mut a array) trim(index int) {
|
|||
#return result;
|
||||
#}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (a array) repeat_to_depth(count int, depth int) array {
|
||||
if count < 0 {
|
||||
panic('array.repeat: count is negative: ${count}')
|
||||
|
@ -297,7 +297,7 @@ pub fn (mut a array) prepend(val voidptr) {
|
|||
}
|
||||
|
||||
// prepend_many prepends another array to this array.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (mut a array) prepend_many(val voidptr, size int) {
|
||||
unsafe { a.insert_many(0, val, size) }
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ pub fn (mut a array) delete_last() {
|
|||
#a.val.arr.arr.pop();
|
||||
}
|
||||
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (a &array) free() {
|
||||
}
|
||||
|
||||
|
|
|
@ -975,7 +975,7 @@ fn test_in_struct() {
|
|||
assert baz.bar[0] == 3
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn test_direct_modification() {
|
||||
mut foo := [2, 0, 5]
|
||||
foo[1] = 3
|
||||
|
@ -1208,7 +1208,7 @@ fn test_array_last() {
|
|||
assert s.last().val == 'a'
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn test_direct_array_access() {
|
||||
mut a := [11, 22, 33, 44]
|
||||
assert a[0] == 11
|
||||
|
@ -1221,7 +1221,7 @@ fn test_direct_array_access() {
|
|||
assert a == [21, 24, 14, 20]
|
||||
}
|
||||
|
||||
[direct_array_access]
|
||||
@[direct_array_access]
|
||||
fn test_direct_array_access_via_ptr() {
|
||||
mut b := [11, 22, 33, 44]
|
||||
unsafe {
|
||||
|
|
|
@ -2,7 +2,7 @@ module builtin
|
|||
|
||||
// used to generate JS throw statements.
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn js_throw(s any) {
|
||||
#throw s
|
||||
|
||||
|
@ -60,7 +60,7 @@ pub fn eprint(s string) {
|
|||
// Exits the process in node, and halts execution in the browser
|
||||
// because `process.exit` is undefined. Workaround for not having
|
||||
// a 'real' way to exit in the browser.
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn exit(c int) {
|
||||
JS.process.exit(c)
|
||||
js_throw('exit(${c})')
|
||||
|
|
|
@ -6,7 +6,7 @@ module builtin
|
|||
|
||||
fn (a any) toString()
|
||||
|
||||
[noreturn]
|
||||
@[noreturn]
|
||||
pub fn panic(s string) {
|
||||
eprintln('V panic: ${s}\n${js_stacktrace()}')
|
||||
exit(1)
|
||||
|
@ -127,7 +127,7 @@ fn trace_error(x string) {
|
|||
|
||||
// error returns a default error instance containing the error given in `message`.
|
||||
// Example: if ouch { return error('an error occurred') }
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn error(message string) IError {
|
||||
// trace_error(message)
|
||||
return &MessageError{
|
||||
|
@ -137,7 +137,7 @@ pub fn error(message string) IError {
|
|||
|
||||
// error_with_code returns a default error instance containing the given `message` and error `code`.
|
||||
// Example: if ouch { return error_with_code('an error occurred', 1) }
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn error_with_code(message string, code int) IError {
|
||||
// trace_error('$message | code: $code')
|
||||
return &MessageError{
|
||||
|
@ -148,7 +148,7 @@ pub fn error_with_code(message string, code int) IError {
|
|||
|
||||
// free allows for manually freeing memory allocated at the address `ptr`.
|
||||
// However, this is a no-op on JS backend
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn free(ptr voidptr) {
|
||||
_ := ptr
|
||||
}
|
||||
|
|
|
@ -30,42 +30,42 @@ pub fn (c u8) repeat(count int) string {
|
|||
return res
|
||||
}
|
||||
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (c u8) is_digit() bool {
|
||||
return c >= `0` && c <= `9`
|
||||
}
|
||||
|
||||
// is_hex_digit returns `true` if the byte is either in range 0-9, a-f or A-F and `false` otherwise.
|
||||
// Example: assert u8(`F`) == true
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (c u8) is_hex_digit() bool {
|
||||
return (c >= `0` && c <= `9`) || (c >= `a` && c <= `f`) || (c >= `A` && c <= `F`)
|
||||
}
|
||||
|
||||
// is_oct_digit returns `true` if the byte is in range 0-7 and `false` otherwise.
|
||||
// Example: assert u8(`7`) == true
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (c u8) is_oct_digit() bool {
|
||||
return c >= `0` && c <= `7`
|
||||
}
|
||||
|
||||
// is_bin_digit returns `true` if the byte is a binary digit (0 or 1) and `false` otherwise.
|
||||
// Example: assert u8(`0`) == true
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (c u8) is_bin_digit() bool {
|
||||
return c == `0` || c == `1`
|
||||
}
|
||||
|
||||
// is_letter returns `true` if the byte is in range a-z or A-Z and `false` otherwise.
|
||||
// Example: assert u8(`V`) == true
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (c u8) is_letter() bool {
|
||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`)
|
||||
}
|
||||
|
||||
// is_alnum returns `true` if the byte is in range a-z, A-Z, 0-9 and `false` otherwise.
|
||||
// Example: assert u8(`V`) == true
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (c u8) is_alnum() bool {
|
||||
return (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || (c >= `0` && c <= `9`)
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ pub fn (c u8) is_alnum() bool {
|
|||
// is_capital returns `true`, if the byte is a Latin capital letter.
|
||||
// Example: assert `H`.is_capital() == true
|
||||
// Example: assert `h`.is_capital() == false
|
||||
[inline]
|
||||
@[inline]
|
||||
pub fn (c u8) is_capital() bool {
|
||||
return c >= `A` && c <= `Z`
|
||||
}
|
||||
|
|
|
@ -9,17 +9,17 @@ module builtin
|
|||
|
||||
pub interface JS.Object {}
|
||||
|
||||
[single_impl]
|
||||
@[single_impl]
|
||||
pub interface JS.BigInt {
|
||||
JS.Any
|
||||
}
|
||||
|
||||
[single_impl]
|
||||
@[single_impl]
|
||||
pub interface JS.Number {
|
||||
JS.Any
|
||||
}
|
||||
|
||||
[single_impl]
|
||||
@[single_impl]
|
||||
pub interface JS.String {
|
||||
JS.Any
|
||||
length JS.Number
|
||||
|
@ -37,7 +37,7 @@ pub interface JS.String {
|
|||
lastIndexOf(needle JS.String) JS.Number
|
||||
}
|
||||
|
||||
[single_impl]
|
||||
@[single_impl]
|
||||
pub interface JS.Boolean {
|
||||
JS.Any
|
||||
length JS.Number
|
||||
|
|
|
@ -36,7 +36,7 @@ fn (mut m map) internal_get(key JS.Any) JS.Any {
|
|||
#map.prototype.set = function(key,val) { map_internal_set(this,key,val); }
|
||||
#map.prototype.has = function (key) { if (typeof key != "string" && '$toJS' in key) { key = key.$toJS() } return key in this.map; }
|
||||
// Removes the mapping of a particular key from the map.
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn (mut m map) delete(key JS.Any) {
|
||||
#let k = '$toJS' in key ? key.$toJS() : key;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ pub interface JS.Promise {
|
|||
finally(callback JS.Any) JS.Promise
|
||||
}
|
||||
|
||||
[use_new]
|
||||
@[use_new]
|
||||
pub fn JS.Promise.prototype.constructor(JS.Any) JS.Promise
|
||||
pub fn JS.Promise.reject(JS.Any) JS.Promise
|
||||
pub fn JS.Promise.resolve(JS.Any) JS.Promise
|
||||
|
@ -16,7 +16,7 @@ pub fn JS.Promise.race(JS.Array) JS.Promise
|
|||
// of an asynchronous operation and its resulting value.
|
||||
pub struct Promise[T] {
|
||||
mut:
|
||||
promise JS.Promise [noinit]
|
||||
promise JS.Promise @[noinit]
|
||||
}
|
||||
|
||||
pub fn promise_new[T](executor fn (resolve fn (T), reject fn (JS.Any))) Promise[T] {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue