parser: check `(mut f Foo)` syntax

pull/4931/head
yuyi 2020-05-17 19:51:18 +08:00 committed by GitHub
parent b138cadbcb
commit 7f4cf08516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
87 changed files with 492 additions and 480 deletions

View File

@ -152,7 +152,7 @@ fn new_gen_vc(flag_options FlagOptions) &GenVC {
}
// WebhookServer init
pub fn (ws mut WebhookServer) init() {
pub fn (mut ws WebhookServer) init() {
mut fp := flag.new_flag_parser(os.args.clone())
flag_options := parse_flags(mut fp)
@ -162,7 +162,7 @@ pub fn (ws mut WebhookServer) init() {
}
// gen webhook
pub fn (ws mut WebhookServer) genhook() {
pub fn (mut ws WebhookServer) genhook() {
ws.gen_vc.generate()
// error in generate
if ws.gen_vc.gen_error {
@ -191,7 +191,7 @@ fn parse_flags(fp mut flag.FlagParser) FlagOptions {
}
// init
fn (gen_vc mut GenVC) init() {
fn (mut gen_vc GenVC) init() {
// purge repos if flag is passed
if gen_vc.options.purge {
gen_vc.purge_repos()
@ -199,7 +199,7 @@ fn (gen_vc mut GenVC) init() {
}
// regenerate
fn (gen_vc mut GenVC) generate() {
fn (mut gen_vc GenVC) generate() {
// set errors to false
gen_vc.gen_error = false
@ -316,17 +316,17 @@ fn (gen_vc mut GenVC) generate() {
}
// only execute when dry_run option is false, otherwise just log
fn (gen_vc mut GenVC) cmd_exec_safe(cmd string) string {
fn (mut gen_vc GenVC) cmd_exec_safe(cmd string) string {
return gen_vc.command_execute(cmd, gen_vc.options.dry_run)
}
// always execute command
fn (gen_vc mut GenVC) cmd_exec(cmd string) string {
fn (mut gen_vc GenVC) cmd_exec(cmd string) string {
return gen_vc.command_execute(cmd, false)
}
// execute command
fn (gen_vc mut GenVC) command_execute(cmd string, dry bool) string {
fn (mut gen_vc GenVC) command_execute(cmd string, dry bool) string {
// if dry is true then dont execute, just log
if dry {
return gen_vc.command_execute_dry(cmd)
@ -352,13 +352,13 @@ fn (gen_vc mut GenVC) command_execute(cmd string, dry bool) string {
}
// just log cmd, dont execute
fn (gen_vc mut GenVC) command_execute_dry(cmd string) string {
fn (mut gen_vc GenVC) command_execute_dry(cmd string) string {
gen_vc.logger.info('cmd (dry): "$cmd"')
return ''
}
// delete repo directories
fn (gen_vc mut GenVC) purge_repos() {
fn (mut gen_vc GenVC) purge_repos() {
// delete old repos (better to be fully explicit here, since these are destructive operations)
mut repo_dir := '$gen_vc.options.work_dir/$git_repo_dir_v'
if os.is_dir(repo_dir) {
@ -373,7 +373,7 @@ fn (gen_vc mut GenVC) purge_repos() {
}
// check if file size is too short
fn (gen_vc mut GenVC) assert_file_exists_and_is_not_too_short(f string, emsg string){
fn (mut gen_vc GenVC) assert_file_exists_and_is_not_too_short(f string, emsg string){
if !os.exists(f) {
gen_vc.logger.error('$err_msg_build: $emsg .')
gen_vc.gen_error = true

View File

@ -27,7 +27,7 @@ pub mut:
message_handler &TestMessageHandler
}
pub fn (mh mut TestMessageHandler) append_message(msg string) {
pub fn (mut mh TestMessageHandler) append_message(msg string) {
mh.mtx.lock()
mh.messages << msg
mh.mtx.unlock()
@ -54,11 +54,11 @@ pub fn new_test_session(_vargs string) TestSession {
}
}
pub fn (ts mut TestSession) init() {
pub fn (mut ts TestSession) init() {
ts.benchmark = benchmark.new_benchmark_no_cstep()
}
pub fn (ts mut TestSession) test() {
pub fn (mut ts TestSession) test() {
ts.init()
mut remaining_files := []string{}
for dot_relative_file in ts.files {
@ -111,7 +111,7 @@ pub fn (ts mut TestSession) test() {
eprintln(term.h_divider('-'))
}
pub fn (m mut TestMessageHandler) display_message() {
pub fn (mut m TestMessageHandler) display_message() {
m.mtx.lock()
defer {
m.messages.clear()

View File

@ -92,7 +92,7 @@ pub mut:
vvlocation string // v.v or compiler/ or cmd/v, depending on v version
}
pub fn (vgit_context mut VGitContext) compile_oldv_if_needed() {
pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
vgit_context.vexename = if os.user_os() == 'windows' { 'v.exe' } else { 'v' }
vgit_context.vexepath = os.real_path(os.join_path(vgit_context.path_v, vgit_context.vexename))
mut command_for_building_v_from_c_source := ''

View File

@ -40,7 +40,7 @@ mut:
cleanup bool // should the tool run a cleanup first
}
fn (c mut Context) compile_oldv_if_needed() {
fn (mut c Context) compile_oldv_if_needed() {
mut vgit_context := vgit.VGitContext{
workdir: c.vgo.workdir
v_repo_url: c.vgo.v_repo_url

View File

@ -36,7 +36,7 @@ fn start_testing(total_number_of_tests int, vfilename string) BenchedTests {
}
// Called before each test_ function, defined in file_test.v
fn (b mut BenchedTests) testing_step_start(stepfunc string) {
fn (mut b BenchedTests) testing_step_start(stepfunc string) {
b.step_func_name = stepfunc.replace('main__', '').replace('__', '.')
b.oks = C.g_test_oks
b.fails = C.g_test_fails
@ -44,7 +44,7 @@ fn (b mut BenchedTests) testing_step_start(stepfunc string) {
}
// Called after each test_ function, defined in file_test.v
fn (b mut BenchedTests) testing_step_end() {
fn (mut b BenchedTests) testing_step_end() {
ok_diff := C.g_test_oks - b.oks
fail_diff := C.g_test_fails - b.fails
// ////////////////////////////////////////////////////////////////
@ -76,7 +76,7 @@ fn (b &BenchedTests) fn_name() string {
}
// Called at the end of the test program produced by `v -stats file_test.v`
fn (b mut BenchedTests) end_testing() {
fn (mut b BenchedTests) end_testing() {
b.bench.stop()
println(INNER_INDENT + b.bench.total_message('running V tests in "' + os.file_name(b.test_suit_file) + '"'))
}

View File

@ -23,7 +23,7 @@ mut:
temp_lines []string // all the temporary expressions/printlns
}
fn (r mut Repl) checks() bool {
fn (mut r Repl) checks() bool {
mut in_string := false
was_indent := r.indent > 0

View File

@ -35,7 +35,6 @@ fn (u User) can_register() bool {
return u.age >= 16
}
fn (u mut User) register() {
fn (mut u User) register() {
u.is_registered = true
}

View File

@ -183,7 +183,7 @@ fn main() {
}
}
fn (g mut Game) init_game() {
fn (mut g Game) init_game() {
g.parse_tetros()
rand.seed(time.now().unix)
g.generate_tetro()
@ -205,7 +205,7 @@ fn (g mut Game) init_game() {
g.state = .running
}
fn (g mut Game) parse_tetros() {
fn (mut g Game) parse_tetros() {
for b_tetros0 in b_tetros {
for b_tetro in b_tetros0 {
for t in parse_binary_tetro(b_tetro) {
@ -215,7 +215,7 @@ fn (g mut Game) parse_tetros() {
}
}
fn (g mut Game) run() {
fn (mut g Game) run() {
for {
if g.state == .running {
g.move_tetro()
@ -226,7 +226,7 @@ fn (g mut Game) run() {
}
}
fn (g mut Game) move_tetro() {
fn (mut g Game) move_tetro() {
// Check each block in current tetro
for block in g.tetro {
y := block.y + g.pos_y + 1
@ -250,7 +250,7 @@ fn (g mut Game) move_tetro() {
g.pos_y++
}
fn (g mut Game) move_right(dx int) bool {
fn (mut g Game) move_right(dx int) bool {
// Reached left/right edge or another tetro?
for i in 0..tetro_size {
tetro := g.tetro[i]
@ -266,13 +266,13 @@ fn (g mut Game) move_right(dx int) bool {
return true
}
fn (g mut Game) delete_completed_lines() {
fn (mut g Game) delete_completed_lines() {
for y := FieldHeight; y >= 1; y-- {
g.delete_completed_line(y)
}
}
fn (g mut Game) delete_completed_line(y int) {
fn (mut g Game) delete_completed_line(y int) {
for x := 1; x <= FieldWidth; x++ {
f := g.field[y]
if f[x] == 0 {
@ -291,7 +291,7 @@ fn (g mut Game) delete_completed_line(y int) {
}
// Place a new tetro on top
fn (g mut Game) generate_tetro() {
fn (mut g Game) generate_tetro() {
g.pos_y = 0
g.pos_x = FieldWidth / 2 - tetro_size / 2
g.tetro_idx = rand.next(b_tetros.len)
@ -300,7 +300,7 @@ fn (g mut Game) generate_tetro() {
}
// Get the right tetro from cache
fn (g mut Game) get_tetro() {
fn (mut g Game) get_tetro() {
idx := g.tetro_idx * tetro_size * tetro_size + g.rotation_idx * tetro_size
g.tetro = g.tetros_cache[idx..idx+tetro_size]
}
@ -342,7 +342,7 @@ fn (g &Game) draw_field() {
}
}
fn (g mut Game) draw_ui() {
fn (mut g Game) draw_ui() {
if g.font_loaded {
g.ft.draw_text(1, 3, g.score.str(), text_cfg)
if g.state == .gameover {
@ -360,7 +360,7 @@ fn (g mut Game) draw_ui() {
//g.gg.draw_rect(0, BlockSize, WinWidth, LimitThickness, UIColor)
}
fn (g mut Game) draw_scene() {
fn (mut g Game) draw_scene() {
g.draw_tetro()
g.draw_field()
g.draw_ui()

View File

@ -17,7 +17,7 @@ fn main() {
vweb.run<App>(port)
}
pub fn (app mut App) init() {
pub fn (mut app App) init() {
// Arbitary mime type.
app.vweb.serve_static('/favicon.ico', 'favicon.ico', 'img/x-icon')
// Automatically make available known static mime types found in given directory.
@ -27,9 +27,9 @@ pub fn (app mut App) init() {
//app.vweb.handle_static('.')
}
pub fn (app mut App) reset() {}
pub fn (mut app App) reset() {}
fn (app mut App) index() {
fn (mut app App) index() {
// We can dynamically specify which assets are to be used in template.
mut am := assets.new_manager()
am.add_css('assets/index.css')
@ -42,10 +42,10 @@ fn (app mut App) index() {
$vweb.html()
}
fn (app mut App) text() {
fn (mut app App) text() {
app.vweb.text('Hello, world from vweb!')
}
fn (app mut App) time() {
fn (mut app App) time() {
app.vweb.text(time.now().format())
}

View File

@ -17,27 +17,27 @@ fn main() {
vweb.run<App>(port)
}
pub fn (app mut App) init() {
pub fn (mut app App) init() {
app.vweb.handle_static('.')
}
pub fn (app mut App) json_endpoint() {
pub fn (mut app App) json_endpoint() {
app.vweb.json('{"a": 3}')
}
pub fn (app mut App) index() {
pub fn (mut app App) index() {
app.cnt++
$vweb.html()
}
pub fn (app mut App) reset() {
pub fn (mut app App) reset() {
}
pub fn (app mut App) text() {
pub fn (mut app App) text() {
app.vweb.text('Hello world')
}
pub fn (app mut App) cookie() {
pub fn (mut app App) cookie() {
app.vweb.set_cookie('cookie', 'test')
app.vweb.text('Headers: $app.vweb.headers')
}

View File

@ -15,7 +15,7 @@ fn main() {
vweb.run<App>(8080)
}
fn (app mut App) index_text() {
fn (mut app App) index_text() {
app.vweb.text('Hello, world from vweb!')
}
@ -31,7 +31,7 @@ fn (app &App) index() {
$vweb.html()
}
pub fn (app mut App) init() {
pub fn (mut app App) init() {
db := pg.connect(pg.Config{
host: '127.0.0.1'
dbname: 'blog'
@ -40,14 +40,14 @@ pub fn (app mut App) init() {
app.db = db
}
pub fn (app mut App) new() {
pub fn (mut app App) new() {
$vweb.html()
}
pub fn (app mut App) reset() {
pub fn (mut app App) reset() {
}
pub fn (app mut App) new_article() {
pub fn (mut app App) new_article() {
title := app.vweb.form['title']
text := app.vweb.form['text']
if title == '' || text == '' {
@ -64,11 +64,11 @@ pub fn (app mut App) new_article() {
app.vweb.redirect('/article/')
}
pub fn (app mut App) articles() {
pub fn (mut app App) articles() {
articles := app.find_all_articles()
app.vweb.json(json.encode(articles))
}
fn (app mut App) time() {
fn (mut app App) time() {
app.vweb.text(time.now().format())
}

View File

@ -90,52 +90,52 @@ pub fn new_benchmark_pointer() &Benchmark {
}
}
pub fn (b mut Benchmark) set_total_expected_steps(n int) {
pub fn (mut b Benchmark) set_total_expected_steps(n int) {
b.nexpected_steps = n
}
pub fn (b mut Benchmark) stop() {
pub fn (mut b Benchmark) stop() {
b.bench_timer.stop()
}
pub fn (b mut Benchmark) step() {
pub fn (mut b Benchmark) step() {
b.step_timer.restart()
if !b.no_cstep {
b.cstep++
}
}
pub fn (b mut Benchmark) fail() {
pub fn (mut b Benchmark) fail() {
b.step_timer.stop()
b.ntotal++
b.nfail++
}
pub fn (b mut Benchmark) ok() {
pub fn (mut b Benchmark) ok() {
b.step_timer.stop()
b.ntotal++
b.nok++
}
pub fn (b mut Benchmark) skip() {
pub fn (mut b Benchmark) skip() {
b.step_timer.stop()
b.ntotal++
b.nskip++
}
pub fn (b mut Benchmark) fail_many(n int) {
pub fn (mut b Benchmark) fail_many(n int) {
b.step_timer.stop()
b.ntotal += n
b.nfail += n
}
pub fn (b mut Benchmark) ok_many(n int) {
pub fn (mut b Benchmark) ok_many(n int) {
b.step_timer.stop()
b.ntotal += n
b.nok += n
}
pub fn (b mut Benchmark) neither_fail_nor_ok() {
pub fn (mut b Benchmark) neither_fail_nor_ok() {
b.step_timer.stop()
}
@ -145,7 +145,7 @@ pub fn start() Benchmark {
return b
}
pub fn (b mut Benchmark) measure(label string) i64 {
pub fn (mut b Benchmark) measure(label string) i64 {
b.ok()
res := b.step_timer.elapsed().microseconds()
println(b.step_message_with_label(BSPENT, 'in $label'))

View File

@ -88,7 +88,7 @@ pub fn (instance BitField) get_bit(bitnr int) int {
}
// set_bit sets bit number 'bit_nr' to 1 (count from 0).
pub fn (instance mut BitField) set_bit(bitnr int) {
pub fn (mut instance BitField) set_bit(bitnr int) {
if bitnr >= instance.size {
return
}
@ -96,7 +96,7 @@ pub fn (instance mut BitField) set_bit(bitnr int) {
}
// clear_bit clears (sets to zero) bit number 'bit_nr' (count from 0).
pub fn (instance mut BitField) clear_bit(bitnr int) {
pub fn (mut instance BitField) clear_bit(bitnr int) {
if bitnr >= instance.size {
return
}
@ -104,7 +104,7 @@ pub fn (instance mut BitField) clear_bit(bitnr int) {
}
// set_all sets all bits in the array to 1.
pub fn (instance mut BitField) set_all() {
pub fn (mut instance BitField) set_all() {
for i in 0..bitnslots(instance.size) {
instance.field[i] = u32(-1)
}
@ -112,7 +112,7 @@ pub fn (instance mut BitField) set_all() {
}
// clear_all clears (sets to zero) all bits in the array.
pub fn (instance mut BitField) clear_all() {
pub fn (mut instance BitField) clear_all() {
for i in 0..bitnslots(instance.size) {
instance.field[i] = u32(0)
}
@ -120,7 +120,7 @@ pub fn (instance mut BitField) clear_all() {
// toggle_bit changes the value (from 0 to 1 or from 1 to 0) of bit
// number 'bit_nr'.
pub fn (instance mut BitField) toggle_bit(bitnr int) {
pub fn (mut instance BitField) toggle_bit(bitnr int) {
if bitnr >= instance.size {
return
}
@ -390,7 +390,7 @@ pub fn (instance BitField) reverse() BitField {
}
// resize changes the size of the bit array to 'new_size'.
pub fn (instance mut BitField) resize(new_size int) {
pub fn (mut instance BitField) resize(new_size int) {
new_bitnslots := bitnslots(new_size)
old_size := instance.size
old_bitnslots := bitnslots(old_size)
@ -433,7 +433,7 @@ pub fn (instance BitField) rotate(offset int) BitField {
// Internal functions
fn (instance mut BitField) clear_tail() {
fn (mut instance BitField) clear_tail() {
tail := instance.size % SLOT_SIZE
if tail != 0 {
// create a mask for the tail

View File

@ -71,7 +71,7 @@ fn new_array_from_c_array_no_alloc(len, cap, elm_size int, c_array voidptr) arra
// Private function. Doubles array capacity if needed
[inline]
fn (a mut array) ensure_cap(required int) {
fn (mut a array) ensure_cap(required int) {
if required <= a.cap {
return
}
@ -110,7 +110,7 @@ pub fn (a array) repeat(count int) array {
}
// array.sort sorts array in-place using given `compare` function as comparator
pub fn (a mut array) sort_with_compare(compare voidptr) {
pub fn (mut a array) sort_with_compare(compare voidptr) {
C.qsort(a.data, a.len, a.element_size, compare)
}
@ -120,7 +120,7 @@ pub fn (a mut array) sort_with_compare(compare voidptr) {
// i := 3
// a.insert(0, &i)
// ----------------------------
pub fn (a mut array) insert(i int, val voidptr) {
pub fn (mut a array) insert(i int, val voidptr) {
$if !no_bounds_checking? {
if i < 0 || i > a.len {
panic('array.insert: index out of range (i == $i, a.len == $a.len)')
@ -136,12 +136,12 @@ pub fn (a mut array) insert(i int, val voidptr) {
// TODO array.prepend is broken
// It depends on array.insert
// -----------------------------
pub fn (a mut array) prepend(val voidptr) {
pub fn (mut a array) prepend(val voidptr) {
a.insert(0, val)
}
// array.delete deletes array element at the given index
pub fn (a mut array) delete(i int) {
pub fn (mut a array) delete(i int) {
$if !no_bounds_checking? {
if i < 0 || i >= a.len {
panic('array.delete: index out of range (i == $i, a.len == $a.len)')
@ -153,13 +153,13 @@ pub fn (a mut array) delete(i int) {
}
// clears the array without deallocating the allocated data
pub fn (a mut array) clear() {
pub fn (mut a array) clear() {
a.len = 0
}
// trims the array length to "index" without modifying the allocated data. If "index" is greater
// than len nothing will be changed
pub fn (a mut array) trim(index int) {
pub fn (mut a array) trim(index int) {
if index < a.len {
a.len = index
}
@ -274,7 +274,7 @@ fn (a &array) slice_clone(start, _end int) array {
}
// Private function. Used to implement assigment to the array element.
fn (a mut array) set(i int, val voidptr) {
fn (mut a array) set(i int, val voidptr) {
$if !no_bounds_checking? {
if i < 0 || i >= a.len {
panic('array.set: index out of range (i == $i, a.len == $a.len)')
@ -283,7 +283,7 @@ fn (a mut array) set(i int, val voidptr) {
C.memcpy(byteptr(a.data) + a.element_size * i, val, a.element_size)
}
fn (a mut array) push(val voidptr) {
fn (mut a array) push(val voidptr) {
a.ensure_cap(a.len + 1)
C.memcpy(byteptr(a.data) + a.element_size * a.len, val, a.element_size)
a.len++
@ -291,7 +291,7 @@ fn (a mut array) push(val voidptr) {
// `val` is array.data
// TODO make private, right now it's used by strings.Builder
pub fn (a3 mut array) push_many(val voidptr, size int) {
pub fn (mut a3 array) push_many(val voidptr, size int) {
if a3.data == val {
// handle `arr << arr`
copy := a3.clone()
@ -392,7 +392,7 @@ fn compare_ints(a, b &int) int {
}
// []int.sort sorts array of int in place in ascending order.
pub fn (a mut []int) sort() {
pub fn (mut a []int) sort() {
a.sort_with_compare(compare_ints)
}

View File

@ -28,7 +28,7 @@ fn (a array) get(i int) voidptr {
}
// Private function. Used to implement assigment to the array element.
fn (a mut array) set(i int, val voidptr) {
fn (mut a array) set(i int, val voidptr) {
if i < 0 || i >= a.len {
panic('array.set: index out of range') //FIXME: (i == $i, a.len == $a.len)')
}

View File

@ -47,17 +47,17 @@ pub fn (a array) repeat(nr_repeats int) array {
return a
}
pub fn (a mut array) sort_with_compare(compare voidptr) {
pub fn (mut a array) sort_with_compare(compare voidptr) {
}
pub fn (a mut array) insert(i int, val voidptr) {
pub fn (mut a array) insert(i int, val voidptr) {
}
pub fn (a mut array) prepend(val voidptr) {
pub fn (mut a array) prepend(val voidptr) {
a.insert(0, val)
}
pub fn (a mut array) delete_elm(idx int) {
pub fn (mut a array) delete_elm(idx int) {
}
/*
@ -132,7 +132,7 @@ pub fn (b []byte) hex() string {
return 'sdf'
}
pub fn (arr mut array) push_many(val voidptr, size int) {
pub fn (mut arr array) push_many(val voidptr, size int) {
}
pub fn free(voidptr) {

View File

@ -10,7 +10,7 @@ pub struct map {
obj voidptr
}
//fn (m mut map) insert(n mut mapnode, key string, val voidptr) {
//fn (mut m map) insert(n mut mapnode, key string, val voidptr) {
//}
//////fn (n & mapnode) find(key string, out voidptr, element_size int) bool{
@ -26,7 +26,7 @@ pub struct map {
//return 0
//}
pub fn (m mut map) keys() []string {
pub fn (mut m map) keys() []string {
return ['']
}
@ -34,7 +34,7 @@ fn (m map) get(key string, out voidptr) bool {
return false
}
pub fn (m mut map) delete(key string) {
pub fn (mut m map) delete(key string) {
}
fn (m map) exists(key string) bool {

View File

@ -209,14 +209,14 @@ pub fn (s string) trim_right(cutset string) string {
// fn print_cur_thread() {
// //C.printf("tid = %08x \n", pthread_self());
// }
pub fn (s mut []string) sort() {
pub fn (mut s []string) sort() {
}
pub fn (s mut []string) sort_ignore_case() {
pub fn (mut s []string) sort_ignore_case() {
}
pub fn (s mut []string) sort_by_len() {
pub fn (mut s []string) sort_by_len() {
}
fn (s string) at(idx int) byte {

View File

@ -119,7 +119,7 @@ fn new_dense_array(value_bytes int) DenseArray {
// Push element to array and return index
// The growth-factor is roughly 1.125 `(x + (x >> 3))`
[inline]
fn (d mut DenseArray) push(key string, value voidptr) u32 {
fn (mut d DenseArray) push(key string, value voidptr) u32 {
if d.cap == d.size {
d.cap += d.cap >> 3
d.keys = &string(C.realloc(d.keys, sizeof(string) * d.cap))
@ -144,7 +144,7 @@ fn (d DenseArray) get(i int) voidptr {
// Move all zeros to the end of the array
// and resize array
fn (d mut DenseArray) zeros_to_end() {
fn (mut d DenseArray) zeros_to_end() {
mut tmp_value := malloc(d.value_bytes)
mut count := u32(0)
for i in 0 .. d.size {
@ -233,7 +233,7 @@ fn (m &map) meta_less(_index u32, _metas u32) (u32,u32) {
}
[inline]
fn (m mut map) meta_greater(_index u32, _metas u32, kvi u32) {
fn (mut m map) meta_greater(_index u32, _metas u32, kvi u32) {
mut meta := _metas
mut index := _index
mut kv_index := kvi
@ -264,7 +264,7 @@ fn (m mut map) meta_greater(_index u32, _metas u32, kvi u32) {
}
}
fn (m mut map) set(key string, value voidptr) {
fn (mut m map) set(key string, value voidptr) {
load_factor := f32(m.size << 1) / f32(m.cap)
if load_factor > max_load_factor {
m.expand()
@ -287,7 +287,7 @@ fn (m mut map) set(key string, value voidptr) {
}
// Doubles the size of the hashmap
fn (m mut map) expand() {
fn (mut m map) expand() {
old_cap := m.cap
m.cap = ((m.cap + 2) << 1) - 2
// Check if any hashbits are left
@ -302,7 +302,7 @@ fn (m mut map) expand() {
}
}
fn (m mut map) rehash() {
fn (mut m map) rehash() {
meta_bytes := sizeof(u32) * (m.cap + 2 + m.extra_metas)
m.metas = &u32(C.realloc(m.metas, meta_bytes))
C.memset(m.metas, 0, meta_bytes)
@ -316,7 +316,7 @@ fn (m mut map) rehash() {
}
}
fn (m mut map) cached_rehash(old_cap u32) {
fn (mut m map) cached_rehash(old_cap u32) {
old_metas := m.metas
m.metas = &u32(vcalloc(sizeof(u32) * (m.cap + 2 + m.extra_metas)))
old_extra_metas := m.extra_metas
@ -370,7 +370,7 @@ fn (m map) exists(key string) bool {
return false
}
pub fn (m mut map) delete(key string) {
pub fn (mut m map) delete(key string) {
mut index,mut meta := m.key_to_index(key)
index,meta = m.meta_less(index, meta)
// Perform backwards shifting

View File

@ -10,7 +10,7 @@ mut:
users map[string]User
}
fn (a mut A) set(key string, val int) {
fn (mut a A) set(key string, val int) {
a.m[key] = val
}

View File

@ -65,7 +65,7 @@ fn new_node() &mapnode {
// This implementation does proactive insertion, meaning
// that splits are done top-down and not bottom-up.
fn (m mut SortedMap) set(key string, value voidptr) {
fn (mut m SortedMap) set(key string, value voidptr) {
mut node := m.root
mut child_index := 0
mut parent := &mapnode(0)
@ -112,7 +112,7 @@ fn (m mut SortedMap) set(key string, value voidptr) {
}
}
fn (n mut mapnode) split_child(child_index int, y mut mapnode) {
fn (mut n mapnode) split_child(child_index int, y mut mapnode) {
mut z := new_node()
z.size = mid_index
y.size = mid_index
@ -186,7 +186,7 @@ fn (n &mapnode) find_key(k string) int {
return idx
}
fn (n mut mapnode) remove_key(k string) bool {
fn (mut n mapnode) remove_key(k string) bool {
idx := n.find_key(k)
if idx < n.size && n.keys[idx] == k {
if isnil(n.children) {
@ -212,7 +212,7 @@ fn (n mut mapnode) remove_key(k string) bool {
}
}
fn (n mut mapnode) remove_from_leaf(idx int) {
fn (mut n mapnode) remove_from_leaf(idx int) {
for i := idx + 1; i < n.size; i++ {
n.keys[i - 1] = n.keys[i]
n.values[i - 1] = n.values[i]
@ -220,7 +220,7 @@ fn (n mut mapnode) remove_from_leaf(idx int) {
n.size--
}
fn (n mut mapnode) remove_from_non_leaf(idx int) {
fn (mut n mapnode) remove_from_non_leaf(idx int) {
k := n.keys[idx]
if &mapnode(n.children[idx]).size >= degree {
mut current := &mapnode(n.children[idx])
@ -246,7 +246,7 @@ fn (n mut mapnode) remove_from_non_leaf(idx int) {
}
}
fn (n mut mapnode) fill(idx int) {
fn (mut n mapnode) fill(idx int) {
if idx != 0 && &mapnode(n.children[idx - 1]).size >= degree {
n.borrow_from_prev(idx)
} else if idx != n.size && &mapnode(n.children[idx + 1]).size >= degree {
@ -258,7 +258,7 @@ fn (n mut mapnode) fill(idx int) {
}
}
fn (n mut mapnode) borrow_from_prev(idx int) {
fn (mut n mapnode) borrow_from_prev(idx int) {
mut child := &mapnode(n.children[idx])
mut sibling := &mapnode(n.children[idx - 1])
for i := child.size - 1; i >= 0; i-- {
@ -281,7 +281,7 @@ fn (n mut mapnode) borrow_from_prev(idx int) {
sibling.size--
}
fn (n mut mapnode) borrow_from_next(idx int) {
fn (mut n mapnode) borrow_from_next(idx int) {
mut child := &mapnode(n.children[idx])
mut sibling := &mapnode(n.children[idx + 1])
child.keys[child.size] = n.keys[idx]
@ -304,7 +304,7 @@ fn (n mut mapnode) borrow_from_next(idx int) {
sibling.size--
}
fn (n mut mapnode) merge(idx int) {
fn (mut n mapnode) merge(idx int) {
mut child := &mapnode(n.children[idx])
sibling := &mapnode(n.children[idx + 1])
child.keys[mid_index] = n.keys[idx]
@ -330,7 +330,7 @@ fn (n mut mapnode) merge(idx int) {
// free(sibling)
}
pub fn (m mut SortedMap) delete(key string) {
pub fn (mut m SortedMap) delete(key string) {
if m.root.size == 0 {
return
}
@ -387,11 +387,11 @@ pub fn (m &SortedMap) keys() []string {
return keys
}
fn (n mut mapnode) free() {
fn (mut n mapnode) free() {
println('TODO')
}
pub fn (m mut SortedMap) free() {
pub fn (mut m SortedMap) free() {
if isnil(m.root) {
return
}

View File

@ -222,7 +222,7 @@ fn compare_rep_index(a, b &RepIndex) int {
}
fn (a mut []RepIndex) sort() {
fn (mut a []RepIndex) sort() {
a.sort_with_compare(compare_rep_index)
}
@ -969,15 +969,15 @@ fn compare_lower_strings(a, b &string) int {
return compare_strings(aa, bb)
}
pub fn (s mut []string) sort() {
pub fn (mut s []string) sort() {
s.sort_with_compare(compare_strings)
}
pub fn (s mut []string) sort_ignore_case() {
pub fn (mut s []string) sort_ignore_case() {
s.sort_with_compare(compare_lower_strings)
}
pub fn (s mut []string) sort_by_len() {
pub fn (mut s []string) sort_by_len() {
s.sort_with_compare(compare_strings_by_len)
}

View File

@ -34,15 +34,15 @@ pub fn (cmd Command) root() Command {
return cmd.parent.root()
}
pub fn (cmd mut Command) add_command(command Command) {
pub fn (mut cmd Command) add_command(command Command) {
cmd.commands << command
}
pub fn (cmd mut Command) add_flag(flag Flag) {
pub fn (mut cmd Command) add_flag(flag Flag) {
cmd.flags << flag
}
pub fn (cmd mut Command) parse(args []string) {
pub fn (mut cmd Command) parse(args []string) {
cmd.add_default_flags()
cmd.add_default_commands()
@ -55,7 +55,7 @@ pub fn (cmd mut Command) parse(args []string) {
cmd.parse_commands()
}
fn (cmd mut Command) add_default_flags() {
fn (mut cmd Command) add_default_flags() {
if !cmd.disable_help && !cmd.flags.contains('help') && !cmd.flags.contains('h') {
cmd.add_flag(help_flag())
}
@ -64,7 +64,7 @@ fn (cmd mut Command) add_default_flags() {
}
}
fn (cmd mut Command) add_default_commands() {
fn (mut cmd Command) add_default_commands() {
if !cmd.disable_help && !cmd.commands.contains('help') {
cmd.add_command(help_cmd())
}
@ -73,7 +73,7 @@ fn (cmd mut Command) add_default_commands() {
}
}
fn (cmd mut Command) parse_flags() {
fn (mut cmd Command) parse_flags() {
for {
if cmd.args.len < 1 || !cmd.args[0].starts_with('-') {
break

View File

@ -64,7 +64,7 @@ pub fn (flags []Flag) get_string_or(name string, or_value string) string {
}
// parse flag value from arguments and return arguments with all consumed element removed
fn (flag mut Flag) parse(args []string) ?[]string {
fn (mut flag Flag) parse(args []string) ?[]string {
if flag.matches(args) {
if flag.flag == .bool {
new_args := flag.parse_bool(args) or { return error(err) }
@ -85,7 +85,7 @@ fn (flag &Flag) matches(args []string) bool {
(flag.abbrev != '' && args[0].starts_with('-${flag.abbrev}'))
}
fn (flag mut Flag) parse_raw(args []string) ?[]string {
fn (mut flag Flag) parse_raw(args []string) ?[]string {
if args[0].len > flag.name.len && args[0].contains('=') {
flag.value = args[0].split('=')[1]
return args[1..]
@ -96,7 +96,7 @@ fn (flag mut Flag) parse_raw(args []string) ?[]string {
return error('missing argument for ${flag.name}')
}
fn (flag mut Flag) parse_bool(args []string) ?[]string {
fn (mut flag Flag) parse_bool(args []string) ?[]string {
if args[0].len > flag.name.len && args[0].contains('=') {
flag.value = args[0].split('=')[1]
return args[1..]

View File

@ -6,22 +6,22 @@ pub fn new() &Clipboard {
}
// copy some text into the clipboard
pub fn (cb mut Clipboard) copy(text string) bool {
pub fn (mut cb Clipboard) copy(text string) bool {
return cb.set_text(text)
}
// get the text from the clipboard
pub fn (cb mut Clipboard) paste() string {
pub fn (mut cb Clipboard) paste() string {
return cb.get_text()
}
// clear the clipboard
pub fn (cb mut Clipboard) clear_all() {
pub fn (mut cb Clipboard) clear_all() {
cb.clear()
}
// destroy the clipboard
pub fn (cb mut Clipboard) destroy() {
pub fn (mut cb Clipboard) destroy() {
cb.free()
}

View File

@ -25,12 +25,12 @@ fn (cb &Clipboard) check_availability() bool {
return cb.pb != C.NULL
}
fn (cb mut Clipboard) clear(){
fn (mut cb Clipboard) clear(){
cb.foo = 0
#[cb->pb clearContents];
}
fn (cb mut Clipboard) free(){
fn (mut cb Clipboard) free(){
cb.foo = 0
//nothing to free
}
@ -43,7 +43,7 @@ fn (cb &Clipboard) has_ownership() bool {
fn C.OSAtomicCompareAndSwapLong()
fn (cb mut Clipboard) set_text(text string) bool {
fn (mut cb Clipboard) set_text(text string) bool {
cb.foo = 0
#NSString *ns_clip;
ret := false
@ -59,7 +59,7 @@ fn (cb mut Clipboard) set_text(text string) bool {
return ret
}
fn (cb mut Clipboard) get_text() string {
fn (mut cb Clipboard) get_text() string {
cb.foo = 0
#NSString *ns_clip;
utf8_clip := byteptr(0)

View File

@ -172,14 +172,14 @@ fn (cb &Clipboard) check_availability() bool {
return cb.display != C.NULL
}
fn (cb mut Clipboard) free() {
fn (mut cb Clipboard) free() {
C.XDestroyWindow(cb.display, cb.window)
cb.window = C.Window(C.None)
//FIX ME: program hangs when closing display
//XCloseDisplay(cb.display)
}
fn (cb mut Clipboard) clear(){
fn (mut cb Clipboard) clear(){
cb.mutex.lock()
C.XSetSelectionOwner(cb.display, cb.selection, C.Window(C.None), C.CurrentTime)
C.XFlush(cb.display)
@ -197,7 +197,7 @@ fn (cb &Clipboard) take_ownership(){
C.XFlush(cb.display)
}
fn (cb mut Clipboard) set_text(text string) bool {
fn (mut cb Clipboard) set_text(text string) bool {
if cb.window == C.Window(C.None) {return false}
cb.mutex.lock()
cb.text = text
@ -210,7 +210,7 @@ fn (cb mut Clipboard) set_text(text string) bool {
return cb.is_owner
}
fn (cb mut Clipboard) get_text() string {
fn (mut cb Clipboard) get_text() string {
if cb.window == C.Window(C.None) {return ""}
if cb.is_owner {
return cb.text
@ -232,7 +232,7 @@ fn (cb mut Clipboard) get_text() string {
// this function is crucial to handling all the different data types
// if we ever support other mimetypes they should be handled here
fn (cb mut Clipboard) transmit_selection(xse &C.XSelectionEvent) bool {
fn (mut cb Clipboard) transmit_selection(xse &C.XSelectionEvent) bool {
if xse.target == cb.get_atom(.targets) {
targets := cb.get_supported_targets()
C.XChangeProperty(xse.display, xse.requestor, xse.property, cb.get_atom(.xa_atom), 32, C.PropModeReplace, targets.data, targets.len)
@ -246,7 +246,7 @@ fn (cb mut Clipboard) transmit_selection(xse &C.XSelectionEvent) bool {
return true
}
fn (cb mut Clipboard) start_listener(){
fn (mut cb Clipboard) start_listener(){
event := C.XEvent{}
mut sent_request := false
mut to_be_requested := C.Atom(0)
@ -325,7 +325,7 @@ fn (cb mut Clipboard) start_listener(){
// Helpers
// Initialize all the atoms we need
fn (cb mut Clipboard) intern_atoms(){
fn (mut cb Clipboard) intern_atoms(){
cb.atoms << C.Atom(4) //XA_ATOM
cb.atoms << C.Atom(31) //XA_STRING
for i, name in atom_names{

View File

@ -17,23 +17,23 @@ pub fn new_primary() &Clipboard {
return &Clipboard{}
}
fn (cb mut Clipboard) set_text(text string) bool {
fn (mut cb Clipboard) set_text(text string) bool {
cb.text = text
cb.is_owner = true
cb.got_text = true
return true
}
fn (cb mut Clipboard) get_text() string {
fn (mut cb Clipboard) get_text() string {
return cb.text
}
fn (cb mut Clipboard) clear(){
fn (mut cb Clipboard) clear(){
cb.text = ''
cb.is_owner = false
}
fn (cb mut Clipboard) free(){
fn (mut cb Clipboard) free(){
}
fn (cb &Clipboard) has_ownership() bool {

View File

@ -79,7 +79,7 @@ pub fn (x &AesCbc) encrypt_blocks(dst mut []byte, src_ []byte) {
copy(x.iv, iv)
}
pub fn (x mut AesCbc) decrypt_blocks(dst mut []byte, src []byte) {
pub fn (mut x AesCbc) decrypt_blocks(dst mut []byte, src []byte) {
if src.len%x.block_size != 0 {
panic('crypto.cipher: input not full blocks')
}

View File

@ -37,7 +37,7 @@ mut:
len u64
}
fn (d mut Digest) reset() {
fn (mut d Digest) reset() {
d.s = [u32(0)].repeat(4)
d.x = [byte(0)].repeat(block_size)
d.s[0] = u32(init0)
@ -55,7 +55,7 @@ pub fn new() &Digest {
return d
}
pub fn (d mut Digest) write(p_ []byte) int {
pub fn (mut d Digest) write(p_ []byte) int {
mut p := p_
nn := p.len
d.len += u64(nn)
@ -98,7 +98,7 @@ pub fn (d &Digest) sum(b_in []byte) []byte {
return b_out
}
pub fn (d mut Digest) checksum() []byte {
pub fn (mut d Digest) checksum() []byte {
// Append 0x80 to the end of the message and then append zeros
// until the length is a multiple of 56 bytes. Finally append
// 8 bytes representing the message length in bits.

View File

@ -49,7 +49,7 @@ pub fn new_cipher(key []byte) ?Cipher {
//
// Deprecated: Reset can't guarantee that the key will be entirely removed from
// the process's memory.
pub fn (c mut Cipher) reset() {
pub fn (mut c Cipher) reset() {
for i in c.s {
c.s[i] = 0
}
@ -59,7 +59,7 @@ pub fn (c mut Cipher) reset() {
// xor_key_stream sets dst to the result of XORing src with the key stream.
// Dst and src must overlap entirely or not at all.
pub fn (c mut Cipher) xor_key_stream(dst mut []byte, src []byte) {
pub fn (mut c Cipher) xor_key_stream(dst mut []byte, src []byte) {
if src.len == 0 {
return
}

View File

@ -39,7 +39,7 @@ mut:
len u64
}
fn (d mut Digest) reset() {
fn (mut d Digest) reset() {
d.x = [byte(0)].repeat(chunk)
d.h = [u32(0)].repeat(5)
d.h[0] = u32(init0)
@ -58,7 +58,7 @@ pub fn new() &Digest {
return d
}
pub fn (d mut Digest) write(p_ []byte) int {
pub fn (mut d Digest) write(p_ []byte) int {
mut p := p_
nn := p.len
d.len += u64(nn)
@ -102,7 +102,7 @@ pub fn (d &Digest) sum(b_in []byte) []byte {
return b_out
}
fn (d mut Digest) checksum() []byte {
fn (mut d Digest) checksum() []byte {
mut len := d.len
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
mut tmp := [byte(0)].repeat(64)

View File

@ -51,7 +51,7 @@ mut:
is224 bool // mark if this digest is SHA-224
}
fn (d mut Digest) reset() {
fn (mut d Digest) reset() {
d.h = [u32(0)].repeat(8)
d.x = [byte(0)].repeat(chunk)
if !d.is224 {
@ -92,7 +92,7 @@ pub fn new224() &Digest {
return d
}
fn (d mut Digest) write(p_ []byte) int {
fn (mut d Digest) write(p_ []byte) int {
mut p := p_
nn := p.len
d.len += u64(nn)
@ -141,7 +141,7 @@ fn (d &Digest) sum(b_in []byte) []byte {
return b_out
}
fn (d mut Digest) checksum() []byte {
fn (mut d Digest) checksum() []byte {
mut len := d.len
// Padding. Add a 1 bit and 0 bits until 56 bytes mod 64.
mut tmp := [byte(0)].repeat(64)

View File

@ -69,7 +69,7 @@ mut:
function crypto.Hash
}
fn (d mut Digest) reset() {
fn (mut d Digest) reset() {
d.h = [u64(0)].repeat(8)
d.x = [byte(0)].repeat(chunk)
match d.function {
@ -146,7 +146,7 @@ fn new384() &Digest {
return new_digest(.sha384)
}
fn (d mut Digest) write(p_ []byte) int {
fn (mut d Digest) write(p_ []byte) int {
mut p := p_
nn := p.len
d.len += u64(nn)
@ -209,7 +209,7 @@ fn (d &Digest) sum(b_in []byte) []byte {
return b_out
}
fn (d mut Digest) checksum() []byte {
fn (mut d Digest) checksum() []byte {
// Padding. Add a 1 bit and 0 bits until 112 bytes mod 128.
mut len := d.len
mut tmp := [byte(0)].repeat(128)

View File

@ -37,7 +37,7 @@ pub fn new_reader(data string) &Reader {
}
// read() reads one row from the csv file
pub fn (r mut Reader) read() ?[]string {
pub fn (mut r Reader) read() ?[]string {
l := r.read_record() or {
return error(err)
}
@ -45,7 +45,7 @@ pub fn (r mut Reader) read() ?[]string {
}
// Once we have multi dimensional array
// pub fn (r mut Reader) read_all() ?[][]string {
// pub fn (mut r Reader) read_all() ?[][]string {
// mut records := []string{}
// for {
// record := r.read_record() or {
@ -60,7 +60,7 @@ pub fn (r mut Reader) read() ?[]string {
// return records
// }
fn (r mut Reader) read_line() ?string {
fn (mut r Reader) read_line() ?string {
// last record
if r.row_pos == r.data.len {
return err_eof
@ -91,7 +91,7 @@ fn (r mut Reader) read_line() ?string {
return line
}
fn (r mut Reader) read_record() ?[]string {
fn (mut r Reader) read_record() ?[]string {
if r.delimiter == r.comment {
return err_comment_is_delim
}

View File

@ -21,7 +21,7 @@ pub fn new_writer() &Writer {
}
// write writes a single record
pub fn (w mut Writer) write(record []string) ?bool {
pub fn (mut w Writer) write(record []string) ?bool {
if !valid_delim(w.delimiter) {
return err_invalid_delim
}
@ -86,6 +86,6 @@ fn (w &Writer) field_needs_quotes(field string) bool {
return false
}
pub fn (w mut Writer) str() string {
pub fn (mut w Writer) str() string {
return w.sb.str()
}

View File

@ -59,7 +59,7 @@ pub fn (eb &EventBus) has_subscriber(name string) bool {
}
// Publisher Methods
fn (pb mut Publisher) publish(name string, sender voidptr, args voidptr) {
fn (mut pb Publisher) publish(name string, sender voidptr, args voidptr) {
for i, event in pb.registry.events {
if event.name == name {
if event.once {
@ -74,7 +74,7 @@ fn (pb mut Publisher) publish(name string, sender voidptr, args voidptr) {
}
}
fn (p mut Publisher) clear_all() {
fn (mut p Publisher) clear_all() {
if p.registry.events.len == 0 {
return
}
@ -84,7 +84,7 @@ fn (p mut Publisher) clear_all() {
}
// Subscriber Methods
pub fn (s mut Subscriber) subscribe(name string, handler EventHandlerFn) {
pub fn (mut s Subscriber) subscribe(name string, handler EventHandlerFn) {
s.registry.events << EventHandler {
name: name
handler: handler
@ -92,7 +92,7 @@ pub fn (s mut Subscriber) subscribe(name string, handler EventHandlerFn) {
}
}
pub fn (s mut Subscriber) subscribe_method(name string, handler EventHandlerFn, receiver voidptr) {
pub fn (mut s Subscriber) subscribe_method(name string, handler EventHandlerFn, receiver voidptr) {
s.registry.events << EventHandler {
name: name
handler: handler
@ -100,7 +100,7 @@ pub fn (s mut Subscriber) subscribe_method(name string, handler EventHandlerFn,
}
}
pub fn (s mut Subscriber) subscribe_once(name string, handler EventHandlerFn) {
pub fn (mut s Subscriber) subscribe_once(name string, handler EventHandlerFn) {
s.registry.events << EventHandler {
name: name
handler: handler
@ -113,7 +113,7 @@ pub fn (s &Subscriber) is_subscribed(name string) bool {
return s.registry.check_subscriber(name)
}
pub fn (s mut Subscriber) unsubscribe(name string, handler EventHandlerFn) {
pub fn (mut s Subscriber) unsubscribe(name string, handler EventHandlerFn) {
// v := voidptr(handler)
for i, event in s.registry.events {
if event.name == name {

View File

@ -100,27 +100,27 @@ pub fn new_flag_parser(args []string) &FlagParser {
}
// change the application name to be used in 'usage' output
pub fn (fs mut FlagParser) application(name string) {
pub fn (mut fs FlagParser) application(name string) {
fs.application_name = name
}
// change the application version to be used in 'usage' output
pub fn (fs mut FlagParser) version(vers string) {
pub fn (mut fs FlagParser) version(vers string) {
fs.application_version = vers
}
// change the application version to be used in 'usage' output
pub fn (fs mut FlagParser) description(desc string) {
pub fn (mut fs FlagParser) description(desc string) {
fs.application_description = desc
}
// in most cases you do not need the first argv for flag parsing
pub fn (fs mut FlagParser) skip_executable() {
pub fn (mut fs FlagParser) skip_executable() {
fs.args.delete(0)
}
// private helper to register a flag
fn (fs mut FlagParser) add_flag(name string, abbr byte, usage string, desc string) {
fn (mut fs FlagParser) add_flag(name string, abbr byte, usage string, desc string) {
fs.flags << Flag{
name: name,
abbr: abbr,
@ -138,7 +138,7 @@ fn (fs mut FlagParser) add_flag(name string, abbr byte, usage string, desc strin
//
// - the name, usage are registered
// - found arguments and corresponding values are removed from args list
fn (fs mut FlagParser) parse_value(longhand string, shorthand byte) []string {
fn (mut fs FlagParser) parse_value(longhand string, shorthand byte) []string {
full := '--$longhand'
mut found_entries := []string{}
mut to_delete := []int{}
@ -190,7 +190,7 @@ fn (fs mut FlagParser) parse_value(longhand string, shorthand byte) []string {
// special: it is allowed to define bool flags without value
// -> '--flag' is parsed as true
// -> '--flag' is equal to '--flag=true'
fn (fs mut FlagParser) parse_bool_value(longhand string, shorthand byte) ?string {
fn (mut fs FlagParser) parse_bool_value(longhand string, shorthand byte) ?string {
full := '--$longhand'
for i, arg in fs.args {
if arg == '--' {
@ -230,7 +230,7 @@ fn (fs mut FlagParser) parse_bool_value(longhand string, shorthand byte) ?string
// bool_opt returns an optional that returns the value associated with the flag.
// In the situation that the flag was not provided, it returns null.
pub fn (fs mut FlagParser) bool_opt(name string, abbr byte, usage string) ?bool {
pub fn (mut fs FlagParser) bool_opt(name string, abbr byte, usage string) ?bool {
fs.add_flag(name, abbr, usage, '<bool>')
parsed := fs.parse_bool_value(name, abbr) or {
return error("parameter '$name' not provided")
@ -245,7 +245,7 @@ pub fn (fs mut FlagParser) bool_opt(name string, abbr byte, usage string) ?bool
// the default value is returned
// version with abbr
//TODO error handling for invalid string to bool conversion
pub fn (fs mut FlagParser) bool(name string, abbr byte, bdefault bool, usage string) bool {
pub fn (mut fs FlagParser) bool(name string, abbr byte, bdefault bool, usage string) bool {
value := fs.bool_opt(name, abbr, usage) or {
return bdefault
}
@ -254,7 +254,7 @@ pub fn (fs mut FlagParser) bool(name string, abbr byte, bdefault bool, usage str
// int_multi returns all instances of values associated with the flags provided
// In the case that none were found, it returns an empty array.
pub fn (fs mut FlagParser) int_multi(name string, abbr byte, usage string) []int {
pub fn (mut fs FlagParser) int_multi(name string, abbr byte, usage string) []int {
fs.add_flag(name, abbr, usage, '<multiple ints>')
parsed := fs.parse_value(name, abbr)
mut value := []int{}
@ -266,7 +266,7 @@ pub fn (fs mut FlagParser) int_multi(name string, abbr byte, usage string) []int
// int_opt returns an optional that returns the value associated with the flag.
// In the situation that the flag was not provided, it returns null.
pub fn (fs mut FlagParser) int_opt(name string, abbr byte, usage string) ?int {
pub fn (mut fs FlagParser) int_opt(name string, abbr byte, usage string) ?int {
fs.add_flag(name, abbr, usage, '<int>')
parsed := fs.parse_value(name, abbr)
if parsed.len == 0 {
@ -282,7 +282,7 @@ pub fn (fs mut FlagParser) int_opt(name string, abbr byte, usage string) ?int {
// the default value is returned
// version with abbr
//TODO error handling for invalid string to int conversion
pub fn (fs mut FlagParser) int(name string, abbr byte, idefault int, usage string) int {
pub fn (mut fs FlagParser) int(name string, abbr byte, idefault int, usage string) int {
value := fs.int_opt(name, abbr, usage) or {
return idefault
}
@ -291,7 +291,7 @@ pub fn (fs mut FlagParser) int(name string, abbr byte, idefault int, usage strin
// float_multi returns all instances of values associated with the flags provided
// In the case that none were found, it returns an empty array.
pub fn (fs mut FlagParser) float_multi(name string, abbr byte, usage string) []f64 {
pub fn (mut fs FlagParser) float_multi(name string, abbr byte, usage string) []f64 {
fs.add_flag(name, abbr, usage, '<multiple floats>')
parsed := fs.parse_value(name, abbr)
mut value := []f64{}
@ -303,7 +303,7 @@ pub fn (fs mut FlagParser) float_multi(name string, abbr byte, usage string) []f
// float_opt returns an optional that returns the value associated with the flag.
// In the situation that the flag was not provided, it returns null.
pub fn (fs mut FlagParser) float_opt(name string, abbr byte, usage string) ?f64 {
pub fn (mut fs FlagParser) float_opt(name string, abbr byte, usage string) ?f64 {
fs.add_flag(name, abbr, usage, '<float>')
parsed := fs.parse_value(name, abbr)
if parsed.len == 0 {
@ -319,7 +319,7 @@ pub fn (fs mut FlagParser) float_opt(name string, abbr byte, usage string) ?f64
// the default value is returned
// version with abbr
//TODO error handling for invalid string to float conversion
pub fn (fs mut FlagParser) float(name string, abbr byte, fdefault f64, usage string) f64 {
pub fn (mut fs FlagParser) float(name string, abbr byte, fdefault f64, usage string) f64 {
value := fs.float_opt(name, abbr, usage) or {
return fdefault
}
@ -328,14 +328,14 @@ pub fn (fs mut FlagParser) float(name string, abbr byte, fdefault f64, usage str
// string_multi returns all instances of values associated with the flags provided
// In the case that none were found, it returns an empty array.
pub fn (fs mut FlagParser) string_multi(name string, abbr byte, usage string) []string {
pub fn (mut fs FlagParser) string_multi(name string, abbr byte, usage string) []string {
fs.add_flag(name, abbr, usage, '<multiple floats>')
return fs.parse_value(name, abbr)
}
// string_opt returns an optional that returns the value associated with the flag.
// In the situation that the flag was not provided, it returns null.
pub fn (fs mut FlagParser) string_opt(name string, abbr byte, usage string) ?string {
pub fn (mut fs FlagParser) string_opt(name string, abbr byte, usage string) ?string {
fs.add_flag(name, abbr, usage, '<string>')
parsed := fs.parse_value(name, abbr)
if parsed.len == 0 {
@ -350,14 +350,14 @@ pub fn (fs mut FlagParser) string_opt(name string, abbr byte, usage string) ?str
// else
// the default value is returned
// version with abbr
pub fn (fs mut FlagParser) string(name string, abbr byte, sdefault string, usage string) string {
pub fn (mut fs FlagParser) string(name string, abbr byte, sdefault string, usage string) string {
value := fs.string_opt(name, abbr, usage) or {
return sdefault
}
return value
}
pub fn (fs mut FlagParser) limit_free_args_to_at_least(n int) {
pub fn (mut fs FlagParser) limit_free_args_to_at_least(n int) {
if n > MAX_ARGS_NUMBER {
panic('flag.limit_free_args_to_at_least expect n to be smaller than $MAX_ARGS_NUMBER')
}
@ -367,7 +367,7 @@ pub fn (fs mut FlagParser) limit_free_args_to_at_least(n int) {
fs.min_free_args = n
}
pub fn (fs mut FlagParser) limit_free_args_to_exactly(n int) {
pub fn (mut fs FlagParser) limit_free_args_to_exactly(n int) {
if n > MAX_ARGS_NUMBER {
panic('flag.limit_free_args_to_exactly expect n to be smaller than $MAX_ARGS_NUMBER')
}
@ -380,7 +380,7 @@ pub fn (fs mut FlagParser) limit_free_args_to_exactly(n int) {
// this will cause an error in finalize() if free args are out of range
// (min, ..., max)
pub fn (fs mut FlagParser) limit_free_args(min, max int) {
pub fn (mut fs FlagParser) limit_free_args(min, max int) {
if min > max {
panic('flag.limit_free_args expect min < max, got $min >= $max')
}
@ -388,7 +388,7 @@ pub fn (fs mut FlagParser) limit_free_args(min, max int) {
fs.max_free_args = max
}
pub fn (fs mut FlagParser) arguments_description(description string){
pub fn (mut fs FlagParser) arguments_description(description string){
fs.args_description = description
}

View File

@ -236,7 +236,7 @@ pub fn set_mode_fill() {
}
/*
fn (ctx mut GG) init_rect_vao() {
fn (mut ctx GG) init_rect_vao() {
ctx.rect_vao = gl.gen_vertex_array()
ctx.rect_vbo = gl.gen_buffer()

View File

@ -124,7 +124,7 @@ pub fn (ctx &GG) draw_text_def(x, y int, text string) {
ctx.draw_text(x, y, text, cfg)
}
pub fn (gg mut GG) init_font() {
pub fn (mut gg GG) init_font() {
// TODO
gg.fons =g_fons
gg.font_normal=g_font_normal

View File

@ -233,19 +233,19 @@ pub fn (w &Window) swap_buffers() {
C.glfwSwapBuffers(w.data)
}
pub fn (w mut Window) onmousemove(cb voidptr) {
pub fn (mut w Window) onmousemove(cb voidptr) {
C.glfwSetCursorPosCallback(w.data, cb)
}
pub fn (w mut Window) set_mouse_button_callback(cb voidptr) {
pub fn (mut w Window) set_mouse_button_callback(cb voidptr) {
C.glfwSetMouseButtonCallback(w.data, cb)
}
pub fn (w mut Window) on_resize(cb voidptr) {
pub fn (mut w Window) on_resize(cb voidptr) {
C.glfwSetWindowSizeCallback(w.data, cb)
}
pub fn (w mut Window) on_click(cb voidptr) {
pub fn (mut w Window) on_click(cb voidptr) {
C.glfwSetMouseButtonCallback(w.data, cb)
}
@ -261,11 +261,11 @@ pub fn post_empty_event() {
C.glfwPostEmptyEvent()
}
pub fn (w mut Window) onkeydown(cb voidptr) {
pub fn (mut w Window) onkeydown(cb voidptr) {
C.glfwSetKeyCallback(w.data, cb)
}
pub fn (w mut Window) onchar(cb voidptr) {
pub fn (mut w Window) onchar(cb voidptr) {
C.glfwSetCharModsCallback(w.data, cb)
}

View File

@ -23,7 +23,7 @@ mut:
table []u32
}
fn(c mut Crc32) generate_table(poly int) {
fn(mut c Crc32) generate_table(poly int) {
for i in 0..256 {
mut crc := u32(i)
for _ in 0..8 {

View File

@ -40,25 +40,25 @@ pub mut:
output_file_name string
}
pub fn (l mut Log) set_level(level Level) {
pub fn (mut l Log) set_level(level Level) {
l.level = level
}
pub fn (l mut Log) set_output_level(level Level) {
pub fn (mut l Log) set_output_level(level Level) {
l.level = level
}
pub fn (l mut Log) set_full_logpath(full_log_path string) {
pub fn (mut l Log) set_full_logpath(full_log_path string) {
rlog_file := os.real_path( full_log_path )
l.set_output_label( os.file_name( rlog_file ) )
l.set_output_path( os.base_dir( rlog_file ) )
}
pub fn (l mut Log) set_output_label(label string){
pub fn (mut l Log) set_output_label(label string){
l.output_label = label
}
pub fn (l mut Log) set_output_path(output_file_path string) {
pub fn (mut l Log) set_output_path(output_file_path string) {
if l.ofile.is_opened() { l.ofile.close() }
l.output_to_file = true
l.output_file_name = os.join_path( os.real_path( output_file_path ) , l.output_label )
@ -68,11 +68,11 @@ pub fn (l mut Log) set_output_path(output_file_path string) {
l.ofile = ofile
}
pub fn (l mut Log) close() {
pub fn (mut l Log) close() {
l.ofile.close()
}
fn (l mut Log) log_file(s string, level Level) {
fn (mut l Log) log_file(s string, level Level) {
timestamp := time.now().format_ss()
e := tag(level)
l.ofile.writeln('$timestamp [$e] $s')
@ -84,7 +84,7 @@ fn (l &Log) log_cli(s string, level Level) {
println('[$f ${t.format_ss()}] $s')
}
fn (l mut Log) send_output(s &string, level Level) {
fn (mut l Log) send_output(s &string, level Level) {
if l.output_to_file {
l.log_file(s, level)
} else {
@ -92,29 +92,29 @@ fn (l mut Log) send_output(s &string, level Level) {
}
}
pub fn (l mut Log) fatal(s string){
pub fn (mut l Log) fatal(s string){
if l.level < .fatal { return }
l.send_output(s, .fatal)
l.ofile.close()
panic('$l.output_label: $s')
}
pub fn (l mut Log) error(s string) {
pub fn (mut l Log) error(s string) {
if l.level < .error { return }
l.send_output(s, .error)
}
pub fn (l mut Log) warn(s string) {
pub fn (mut l Log) warn(s string) {
if l.level < .warn { return }
l.send_output(s, .warn)
}
pub fn (l mut Log) info(s string) {
pub fn (mut l Log) info(s string) {
if l.level < .info { return }
l.send_output(s, .info)
}
pub fn (l mut Log) debug(s string) {
pub fn (mut l Log) debug(s string) {
if l.level < .debug { return }
l.send_output(s, .debug)
}

View File

@ -124,10 +124,10 @@ pub fn cmp(a Number, b Number) int {
pub fn (a Number) is_zero() bool {
return C.bignum_is_zero(&a) != 0
}
pub fn (a mut Number) inc() {
pub fn (mut a Number) inc() {
C.bignum_inc(a)
}
pub fn (a mut Number) dec() {
pub fn (mut a Number) dec() {
C.bignum_dec(a)
}
pub fn pow(a Number, b Number) Number {

View File

@ -23,7 +23,7 @@ pub fn new_connection(host, username, password, dbname string) ?Connection {
return Connection{ host, 0, username, password, dbname, 0, instance }
}
pub fn (conn mut Connection) connect() ?bool {
pub fn (mut conn Connection) connect() ?bool {
mut instance := C.mysql_init(0)
if !isnil(conn.conn) {
instance = conn.conn

View File

@ -13,7 +13,7 @@ mut:
text string
}
fn (s mut ChunkScanner) read_chunk_size() int {
fn (mut s ChunkScanner) read_chunk_size() int {
mut n := 0
for {
if s.pos >= s.text.len {
@ -43,11 +43,11 @@ fn unhex(c byte) byte {
return 0
}
fn (s mut ChunkScanner) skip_crlf() {
fn (mut s ChunkScanner) skip_crlf() {
s.pos += 2
}
fn (s mut ChunkScanner) read_chunk(chunksize int) string {
fn (mut s ChunkScanner) read_chunk(chunksize int) string {
startpos := s.pos
s.pos += chunksize
return s.text[startpos..s.pos]
@ -71,4 +71,3 @@ pub fn decode(text string) string {
cscanner.skip_crlf()
return sb.str()
}

View File

@ -651,7 +651,7 @@ fn parse_host(host string) ?string {
// - set_path('/foo%2fbar') will set path='/foo/bar' and raw_path='/foo%2fbar'
// set_path will return an error only if the provided path contains an invalid
// escaping.
pub fn (u mut URL) set_path(p string) ?bool {
pub fn (mut u URL) set_path(p string) ?bool {
path := unescape(p, .encode_path) or {
return error(err)
}

View File

@ -61,7 +61,7 @@ pub fn (v &Values) get_all(key string) []string {
// set sets the key to value. It replaces any existing
// values.
pub fn (v mut Values) set(key, value string) {
pub fn (mut v Values) set(key, value string) {
mut a := v.data[key]
a.data = [value]
v.data[key] = a
@ -70,7 +70,7 @@ pub fn (v mut Values) set(key, value string) {
// add adds the value to key. It appends to any existing
// values associated with key.
pub fn (v mut Values) add(key, value string) {
pub fn (mut v Values) add(key, value string) {
mut a := v.data[key]
if a.data.len == 0 {
a.data = []
@ -81,8 +81,7 @@ pub fn (v mut Values) add(key, value string) {
}
// del deletes the values associated with key.
pub fn (v mut Values) del(key string) {
pub fn (mut v Values) del(key string) {
v.data.delete(key)
v.size = v.data.size
}

View File

@ -1,6 +1,6 @@
module websocket
fn (ws mut Client) read_handshake(seckey string){
fn (mut ws Client) read_handshake(seckey string){
l.d("reading handshake...")
mut bytes_read := 0
max_buffer := 1024
@ -21,7 +21,7 @@ fn (ws mut Client) read_handshake(seckey string){
ws.handshake_handler(string(byteptr(buffer)), seckey)
}
fn (ws mut Client) handshake_handler(handshake_response, seckey string){
fn (mut ws Client) handshake_handler(handshake_response, seckey string){
l.d("handshake_handler:\r\n${handshake_response}")
lines := handshake_response.split_into_lines()

View File

@ -2,7 +2,7 @@ module websocket
fn C.write() int
fn (ws mut Client) write_to_server(buf voidptr, len int) int {
fn (mut ws Client) write_to_server(buf voidptr, len int) int {
mut bytes_written := 0
ws.write_lock.lock()
bytes_written = if ws.is_ssl {

View File

@ -21,7 +21,7 @@ fn C.SSL_CTX_free()
fn C.SSL_write() int
fn C.SSL_read() int
fn (ws mut Client) connect_ssl(){
fn (mut ws Client) connect_ssl(){
l.i("Using secure SSL connection")
C.SSL_load_error_strings()
C.SSL_library_init()

View File

@ -23,7 +23,7 @@ pub fn utf8_validate(data byteptr, len int) bool {
return !state.failed && state.subindex <= 0
}
fn (s mut Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
fn (mut s Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
if s.subindex == 0 || (s.index > 1 && s.subindex == 1) || (s.index >= 6 && s.subindex == 2) {
if (s.subindex == 0 && r0) || (s.subindex == 1 && r1) || (s.subindex == 2 && is_tail) {
s.subindex++
@ -46,7 +46,7 @@ fn (s mut Utf8State) seq(r0 bool, r1 bool, is_tail bool) bool {
return false
}
fn (s mut Utf8State) next_state (c byte) {
fn (mut s Utf8State) next_state (c byte) {
//sequence 1
if s.index == 0 {
if (c >= 0x00 + 1 && c <= 0x7F) || c == 0x00 {

View File

@ -115,7 +115,7 @@ fn (ws &Client) parse_uri() &Uri {
}
}
pub fn (ws mut Client) connect() int {
pub fn (mut ws Client) connect() int {
match ws.state {
.connected {
l.f("connect: websocket already connected")
@ -191,7 +191,7 @@ pub fn (ws mut Client) connect() int {
return 0
}
pub fn (ws mut Client) close(code int, message string){
pub fn (mut ws Client) close(code int, message string){
if ws.state != .closed && ws.socket.sockfd > 1 {
ws.lock.lock()
@ -248,7 +248,7 @@ pub fn (ws mut Client) close(code int, message string){
}
}
pub fn (ws mut Client) write(payload byteptr, payload_len int, code OPCode) int {
pub fn (mut ws Client) write(payload byteptr, payload_len int, code OPCode) int {
if ws.state != .open {
ws.send_error_event("WebSocket closed. Cannot write.")
goto free_data
@ -319,7 +319,7 @@ pub fn (ws mut Client) write(payload byteptr, payload_len int, code OPCode) int
return bytes_written
}
pub fn (ws mut Client) listen() {
pub fn (mut ws Client) listen() {
l.i("Starting listener...")
for ws.state == .open {
ws.read()
@ -327,7 +327,7 @@ pub fn (ws mut Client) listen() {
l.i("Listener stopped as websocket was closed.")
}
pub fn (ws mut Client) read() int {
pub fn (mut ws Client) read() int {
mut bytes_read := u64(0)
initial_buffer := u64(256)
@ -601,7 +601,7 @@ pub fn (ws mut Client) read() int {
return -1
}
fn (ws mut Client) send_control_frame(code OPCode, frame_typ string, payload []byte) int {
fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []byte) int {
if ws.socket.sockfd <= 0 {
l.e("No socket opened.")
goto free_data

View File

@ -325,7 +325,7 @@ pub fn open_file(path string, mode string, options ...int) ?File {
}
}
pub fn (f mut File) write_bytes_at(data voidptr, size, pos int) {
pub fn (mut f File) write_bytes_at(data voidptr, size, pos int) {
//$if linux {
//}
//$else {
@ -335,7 +335,7 @@ pub fn (f mut File) write_bytes_at(data voidptr, size, pos int) {
//}
}
pub fn (f mut File) flush() {
pub fn (mut f File) flush() {
if !f.opened {
return
}

View File

@ -128,12 +128,12 @@ pub fn create(path string) ?File {
}
/*
pub fn (f mut File) fseek(pos, mode int) {
pub fn (mut f File) fseek(pos, mode int) {
}
*/
pub fn (f mut File) write(s string) {
pub fn (mut f File) write(s string) {
if !f.opened {
return
}
@ -149,7 +149,7 @@ pub fn (f mut File) write(s string) {
// C.fwrite(s.str, 1, s.len, f.cfile)
}
pub fn (f mut File) writeln(s string) {
pub fn (mut f File) writeln(s string) {
if !f.opened {
return
}
@ -237,7 +237,7 @@ pub fn get_error_msg(code int) string {
// convert any value to []byte (LittleEndian) and write it
// for example if we have write(7, 4), "07 00 00 00" gets written
// write(0x1234, 2) => "34 12"
pub fn (f mut File) write_bytes(data voidptr, size int) {
pub fn (mut f File) write_bytes(data voidptr, size int) {
/*
$if linux {
$if !android {
@ -249,7 +249,7 @@ pub fn (f mut File) write_bytes(data voidptr, size int) {
C.fwrite(data, 1, size, f.cfile)
}
pub fn (f mut File) close() {
pub fn (mut f File) close() {
if !f.opened {
return
}

View File

@ -155,14 +155,14 @@ pub fn create(path string) ?File {
return file
}
pub fn (f mut File) write(s string) {
pub fn (mut f File) write(s string) {
if !f.opened {
return
}
C.fputs(s.str, f.cfile)
}
pub fn (f mut File) writeln(s string) {
pub fn (mut f File) writeln(s string) {
if !f.opened {
return
}
@ -344,11 +344,11 @@ pub fn symlink(origin, target string) ?bool {
return error(get_error_msg(int(C.GetLastError())))
}
pub fn (f mut File) write_bytes(data voidptr, size int) {
pub fn (mut f File) write_bytes(data voidptr, size int) {
C.fwrite(data, 1, size, f.cfile)
}
pub fn (f mut File) close() {
pub fn (mut f File) close() {
if !f.opened {
return
}

View File

@ -9,7 +9,7 @@ mut:
}
[inline]
pub fn (r mut Request) parse_request(s string, headers *C.phr_header_t, max_headers int) int {
pub fn (mut r Request) parse_request(s string, headers *C.phr_header_t, max_headers int) int {
method_len := u64(0)
path_len := u64(0)
minor_version := 0
@ -33,7 +33,7 @@ pub fn (r mut Request) parse_request(s string, headers *C.phr_header_t, max_head
}
[inline]
pub fn (r mut Request) parse_request_path(s string) int {
pub fn (mut r Request) parse_request_path(s string) int {
method_len := u64(0)
path_len := u64(0)
@ -50,7 +50,7 @@ pub fn (r mut Request) parse_request_path(s string) int {
}
[inline]
pub fn (r mut Request) parse_request_path_pipeline(s string) int {
pub fn (mut r Request) parse_request_path_pipeline(s string) int {
method_len := u64(0)
path_len := u64(0)

View File

@ -10,13 +10,13 @@ mut:
}
[inline]
pub fn (r mut Response) http_ok() &Response {
pub fn (mut r Response) http_ok() &Response {
r.buf += cpy_str(r.buf, "HTTP/1.1 200 OK\r\n")
return r
}
[inline]
pub fn (r mut Response) header(k, v string) &Response {
pub fn (mut r Response) header(k, v string) &Response {
r.buf += cpy_str(r.buf, k)
r.buf += cpy_str(r.buf, ": ")
r.buf += cpy_str(r.buf, v)
@ -25,7 +25,7 @@ pub fn (r mut Response) header(k, v string) &Response {
}
[inline]
pub fn (r mut Response) header_date() &Response {
pub fn (mut r Response) header_date() &Response {
r.buf += cpy_str(r.buf, "Date: ")
r.buf += cpy(r.buf, r.date, 29)
r.buf += cpy_str(r.buf, "\r\n")
@ -33,13 +33,13 @@ pub fn (r mut Response) header_date() &Response {
}
[inline]
pub fn (r mut Response) header_server() &Response {
pub fn (mut r Response) header_server() &Response {
r.buf += cpy_str(r.buf, "Server: V\r\n")
return r
}
[inline]
pub fn (r mut Response) content_type(s string) &Response {
pub fn (mut r Response) content_type(s string) &Response {
r.buf += cpy_str(r.buf, "Content-Type: ")
r.buf += cpy_str(r.buf, s)
r.buf += cpy_str(r.buf, "\r\n")
@ -47,19 +47,19 @@ pub fn (r mut Response) content_type(s string) &Response {
}
[inline]
pub fn (r mut Response) plain() &Response {
pub fn (mut r Response) plain() &Response {
r.buf += cpy_str(r.buf, "Content-Type: text/plain\r\n")
return r
}
[inline]
pub fn (r mut Response) json() &Response {
pub fn (mut r Response) json() &Response {
r.buf += cpy_str(r.buf, "Content-Type: application/json\r\n")
return r
}
[inline]
pub fn (r mut Response) body(body string) {
pub fn (mut r Response) body(body string) {
r.buf += cpy_str(r.buf, "Content-Length: ")
r.buf += C.u64toa(r.buf, body.len)
r.buf += cpy_str(r.buf, "\r\n\r\n")
@ -67,27 +67,27 @@ pub fn (r mut Response) body(body string) {
}
[inline]
pub fn (r mut Response) http_404() {
pub fn (mut r Response) http_404() {
r.buf += cpy_str(r.buf, 'HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n')
}
[inline]
pub fn (r mut Response) http_405() {
pub fn (mut r Response) http_405() {
r.buf += cpy_str(r.buf, 'HTTP/1.1 405 Method Not Allowed\r\nContent-Length: 0\r\n\r\n')
}
[inline]
pub fn (r mut Response) http_500() {
pub fn (mut r Response) http_500() {
r.buf += cpy_str(r.buf, 'HTTP/1.1 500 Internal Server Error\r\nContent-Length: 0\r\n\r\n')
}
[inline]
pub fn (r mut Response) raw(response string) {
pub fn (mut r Response) raw(response string) {
r.buf += cpy_str(r.buf, response)
}
[inline]
pub fn (r mut Response) end() int {
pub fn (mut r Response) end() int {
n := int(r.buf - r.buf_start)
if C.write(r.fd, r.buf_start, n) != n {
return -1

View File

@ -33,7 +33,7 @@ pub fn new_pcg32(initstate u64, initseq u64) Pcg32 {
[inline]
pub fn (rng mut Pcg32) next() u32 {
pub fn (mut rng Pcg32) next() u32 {
oldstate := rng.state
rng.state = oldstate * (6364136223846793005) + rng.inc
xorshifted := u32(((oldstate>>u64(18)) ^ oldstate)>>u64(27))
@ -49,7 +49,7 @@ pub fn (rng mut Pcg32) next() u32 {
[inline]
pub fn (rng mut Pcg32) bounded_next(bound u32) u32 {
pub fn (mut rng Pcg32) bounded_next(bound u32) u32 {
// To avoid bias, we need to make the range of the RNG a multiple of
// bound, which we do by dropping output less than a threshold.
threshold := (-bound % bound)
@ -66,4 +66,3 @@ pub fn (rng mut Pcg32) bounded_next(bound u32) u32 {
}
return u32(0)
}

View File

@ -24,7 +24,7 @@ pub fn new_splitmix64(seed u64) Splitmix64 {
[inline]
pub fn (rng mut Splitmix64) next() u64 {
pub fn (mut rng Splitmix64) next() u64 {
rng.state += (0x9e3779b97f4a7c15)
mut z := rng.state
z = (z ^ ((z>>u64(30)))) * (0xbf58476d1ce4e5b9)
@ -40,7 +40,7 @@ pub fn (rng mut Splitmix64) next() u64 {
[inline]
pub fn (rng mut Splitmix64) bounded_next(bound u64) u64 {
pub fn (mut rng Splitmix64) bounded_next(bound u64) u64 {
threshold := -bound % bound
for {
r := rng.next()
@ -50,4 +50,3 @@ pub fn (rng mut Splitmix64) bounded_next(bound u64) u64 {
}
return u64(0)
}

View File

@ -13,7 +13,7 @@ import os
// Only use standard os.get_line
// Need implementation for readline capabilities
pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring {
r.current = ''.ustring()
r.cursor = 0
r.prompt = prompt
@ -38,7 +38,7 @@ pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
}
// Returns the string from the utf8 ustring
pub fn (r mut Readline) read_line(prompt string) ?string {
pub fn (mut r Readline) read_line(prompt string) ?string {
s := r.read_line_utf8(prompt) or {
return error(err)
}

View File

@ -15,7 +15,7 @@ import os
// Only use standard os.get_line
// Need implementation for readline capabilities
pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring {
r.current = ''.ustring()
r.cursor = 0
r.prompt = prompt
@ -43,7 +43,7 @@ pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
}
// Returns the string from the utf8 ustring
pub fn (r mut Readline) read_line(prompt string) ?string {
pub fn (mut r Readline) read_line(prompt string) ?string {
s := r.read_line_utf8(prompt) or {
return error(err)
}

View File

@ -42,7 +42,7 @@ fn C.raise()
// Enable the raw mode of the terminal
// In raw mode all keypresses are directly sent to the program and no interpretation is done
// Catches the SIGUSER (CTRL+C) Signal
pub fn (r mut Readline) enable_raw_mode() {
pub fn (mut r Readline) enable_raw_mode() {
if C.tcgetattr(0, &r.orig_termios) == -1 {
r.is_tty = false
r.is_raw = false
@ -61,7 +61,7 @@ pub fn (r mut Readline) enable_raw_mode() {
// Enable the raw mode of the terminal
// Does not catch the SIGUSER (CTRL+C) Signal
pub fn (r mut Readline) enable_raw_mode_nosig() {
pub fn (mut r Readline) enable_raw_mode_nosig() {
if C.tcgetattr(0, &r.orig_termios) == -1 {
r.is_tty = false
r.is_raw = false
@ -79,7 +79,7 @@ pub fn (r mut Readline) enable_raw_mode_nosig() {
}
// Disable the raw mode of the terminal
pub fn (r mut Readline) disable_raw_mode() {
pub fn (mut r Readline) disable_raw_mode() {
if r.is_raw {
C.tcsetattr(0, C.TCSADRAIN, &r.orig_termios)
r.is_raw = false
@ -95,7 +95,7 @@ pub fn (r Readline) read_char() int {
// Will loop and ingest characters until EOF or Enter
// Returns the completed line as utf8 ustring
// Will return an error if line is empty
pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring {
r.current = ''.ustring()
r.cursor = 0
r.prompt = prompt
@ -132,7 +132,7 @@ pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
}
// Returns the string from the utf8 ustring
pub fn (r mut Readline) read_line(prompt string) ?string {
pub fn (mut r Readline) read_line(prompt string) ?string {
s := r.read_line_utf8(prompt) or {
return error(err)
}
@ -272,7 +272,7 @@ fn (r Readline) analyse_extended_control_no_eat(last_c byte) Action {
return .nothing
}
fn (r mut Readline) execute(a Action, c int) bool {
fn (mut r Readline) execute(a Action, c int) bool {
match a {
.eof { return r.eof() }
.insert_character { r.insert_character(c) }
@ -336,7 +336,7 @@ fn calculate_screen_position(x_in int, y_in int, screen_columns int, char_count
}
// Will redraw the line
fn (r mut Readline) refresh_line() {
fn (mut r Readline) refresh_line() {
mut end_of_input := [0, 0]
end_of_input = calculate_screen_position(r.prompt.len, 0, get_screen_columns(), r.current.len, end_of_input)
end_of_input[1] += r.current.count('\n'.ustring())
@ -355,7 +355,7 @@ fn (r mut Readline) refresh_line() {
}
// End the line without a newline
fn (r mut Readline) eof() bool {
fn (mut r Readline) eof() bool {
r.previous_lines.insert(1, r.current)
r.cursor = r.current.len
if r.is_tty {
@ -364,7 +364,7 @@ fn (r mut Readline) eof() bool {
return true
}
fn (r mut Readline) insert_character(c int) {
fn (mut r Readline) insert_character(c int) {
if !r.overwrite || r.cursor == r.current.len {
r.current = r.current.left(r.cursor).ustring().add( utf32_to_str(u32(c)).ustring() ).add( r.current.right(r.cursor).ustring() )
} else {
@ -378,7 +378,7 @@ fn (r mut Readline) insert_character(c int) {
}
// Removes the character behind cursor.
fn (r mut Readline) delete_character() {
fn (mut r Readline) delete_character() {
if r.cursor <= 0 {
return
}
@ -388,7 +388,7 @@ fn (r mut Readline) delete_character() {
}
// Removes the character in front of cursor.
fn (r mut Readline) suppr_character() {
fn (mut r Readline) suppr_character() {
if r.cursor > r.current.len {
return
}
@ -397,7 +397,7 @@ fn (r mut Readline) suppr_character() {
}
// Add a line break then stops the main loop
fn (r mut Readline) commit_line() bool {
fn (mut r Readline) commit_line() bool {
r.previous_lines.insert(1, r.current)
a := '\n'.ustring()
r.current = r.current.add( a )
@ -409,26 +409,26 @@ fn (r mut Readline) commit_line() bool {
return true
}
fn (r mut Readline) move_cursor_left() {
fn (mut r Readline) move_cursor_left() {
if r.cursor > 0 {
r.cursor--
r.refresh_line()
}
}
fn (r mut Readline) move_cursor_right() {
fn (mut r Readline) move_cursor_right() {
if r.cursor < r.current.len {
r.cursor++
r.refresh_line()
}
}
fn (r mut Readline) move_cursor_begining() {
fn (mut r Readline) move_cursor_begining() {
r.cursor = 0
r.refresh_line()
}
fn (r mut Readline) move_cursor_end() {
fn (mut r Readline) move_cursor_end() {
r.cursor = r.current.len
r.refresh_line()
}
@ -439,7 +439,7 @@ fn (r Readline) is_break_character(c string) bool {
return break_characters.contains(c)
}
fn (r mut Readline) move_cursor_word_left() {
fn (mut r Readline) move_cursor_word_left() {
if r.cursor > 0 {
for ; r.cursor > 0 && r.is_break_character(r.current.at(r.cursor - 1)); r.cursor-- {}
for ; r.cursor > 0 && !r.is_break_character(r.current.at(r.cursor - 1)); r.cursor-- {}
@ -447,7 +447,7 @@ fn (r mut Readline) move_cursor_word_left() {
}
}
fn (r mut Readline) move_cursor_word_right() {
fn (mut r Readline) move_cursor_word_right() {
if r.cursor < r.current.len {
for ; r.cursor < r.current.len && r.is_break_character(r.current.at(r.cursor)); r.cursor++ {}
for ; r.cursor < r.current.len && !r.is_break_character(r.current.at(r.cursor)); r.cursor++ {}
@ -455,17 +455,17 @@ fn (r mut Readline) move_cursor_word_right() {
}
}
fn (r mut Readline) switch_overwrite() {
fn (mut r Readline) switch_overwrite() {
r.overwrite = !r.overwrite
}
fn (r mut Readline) clear_screen() {
fn (mut r Readline) clear_screen() {
term.set_cursor_position(1, 1)
term.erase_clear()
r.refresh_line()
}
fn (r mut Readline) history_previous() {
fn (mut r Readline) history_previous() {
if r.search_index + 2 >= r.previous_lines.len {
return
}
@ -478,7 +478,7 @@ fn (r mut Readline) history_previous() {
r.refresh_line()
}
fn (r mut Readline) history_next() {
fn (mut r Readline) history_next() {
if r.search_index <= 0 {
return
}
@ -488,7 +488,7 @@ fn (r mut Readline) history_next() {
r.refresh_line()
}
fn (r mut Readline) suspend() {
fn (mut r Readline) suspend() {
C.raise(C.SIGSTOP)
r.refresh_line()
}

View File

@ -15,7 +15,7 @@ import os
// Only use standard os.get_line
// Need implementation for readline capabilities
pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring {
r.current = ''.ustring()
r.cursor = 0
r.prompt = prompt
@ -43,7 +43,7 @@ pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
}
// Returns the string from the utf8 ustring
pub fn (r mut Readline) read_line(prompt string) ?string {
pub fn (mut r Readline) read_line(prompt string) ?string {
s := r.read_line_utf8(prompt) or {
return error(err)
}

View File

@ -13,7 +13,7 @@ import os
// Only use standard os.get_line
// Need implementation for readline capabilities
pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
pub fn (mut r Readline) read_line_utf8(prompt string) ?ustring {
r.current = ''.ustring()
r.cursor = 0
r.prompt = prompt
@ -38,7 +38,7 @@ pub fn (r mut Readline) read_line_utf8(prompt string) ?ustring {
}
// Returns the string from the utf8 ustring
pub fn (r mut Readline) read_line(prompt string) ?string {
pub fn (mut r Readline) read_line(prompt string) ?string {
s := r.read_line_utf8(prompt) or {
return error(err)
}

View File

@ -262,7 +262,7 @@ mut:
}
[inline]
fn (tok mut Token) reset() {
fn (mut tok Token) reset() {
tok.rep = 0
}
@ -330,7 +330,7 @@ pub mut:
// Reset RE object
//[inline]
fn (re mut RE) reset(){
fn (mut re RE) reset(){
re.cc_index = 0
mut i := 0
@ -352,7 +352,7 @@ fn (re mut RE) reset(){
// reset for search mode fail
// gcc bug, dont use [inline] or go 5 time slower
fn (re mut RE) reset_src(){
fn (mut re RE) reset_src(){
mut i := 0
for i < re.prog.len {
re.prog[i].group_rep = 0 // clear repetition of the group
@ -544,7 +544,7 @@ fn (re RE) check_char_class(pc int, ch u32) bool {
}
// parse_char_class return (index, str_len, cc_type) of a char class [abcm-p], char class start after the [ char
fn (re mut RE) parse_char_class(in_txt string, in_i int) (int, int, u32) {
fn (mut re RE) parse_char_class(in_txt string, in_i int) (int, int, u32) {
mut status := CharClass_parse_state.start
mut i := in_i
@ -897,7 +897,7 @@ fn (re RE) parse_groups(in_txt string, in_i int) (int, bool, string, int) {
// main compiler
//
// compile return (return code, index) where index is the index of the error in the query string if return code is an error code
pub fn (re mut RE) compile(in_txt string) (int,int) {
pub fn (mut re RE) compile(in_txt string) (int,int) {
mut i := 0 // input string index
mut pc := 0 // program counter
mut tmp_code := u32(0)
@ -1467,7 +1467,7 @@ pub mut:
match_first int = -1
}
pub fn (re mut RE) match_base(in_txt byteptr, in_txt_len int ) (int,int) {
pub fn (mut re RE) match_base(in_txt byteptr, in_txt_len int ) (int,int) {
// result status
mut result := NO_MATCH_FOUND // function return
mut first_match := -1 //index of the first match
@ -2201,7 +2201,7 @@ pub fn new_regex_by_size(mult int) RE {
// Matchers
//
pub fn (re mut RE) match_string(in_txt string) (int,int) {
pub fn (mut re RE) match_string(in_txt string) (int,int) {
start, end := re.match_base(in_txt.str,in_txt.len)
if start >= 0 && end > start {
if (re.flag & F_MS) != 0 && start > 0 {
@ -2223,7 +2223,7 @@ pub fn (re mut RE) match_string(in_txt string) (int,int) {
//
// find try to find the first match in the input string
pub fn (re mut RE) find(in_txt string) (int,int) {
pub fn (mut re RE) find(in_txt string) (int,int) {
old_flag := re.flag
re.flag |= F_SRC // enable search mode
start, end := re.match_base(in_txt.str, in_txt.len)
@ -2235,7 +2235,7 @@ pub fn (re mut RE) find(in_txt string) (int,int) {
}
// find all the non overlapping occurrences of the match pattern
pub fn (re mut RE) find_all(in_txt string) []int {
pub fn (mut re RE) find_all(in_txt string) []int {
mut i := 0
mut res := []int{}
mut ls := -1
@ -2257,7 +2257,7 @@ pub fn (re mut RE) find_all(in_txt string) []int {
}
// replace return a string where the matches are replaced with the replace string
pub fn (re mut RE) replace(in_txt string, repl string) string {
pub fn (mut re RE) replace(in_txt string, repl string) string {
pos := re.find_all(in_txt)
if pos.len > 0 {
mut res := ""

View File

@ -61,11 +61,11 @@ pub mut:
_end_canary u32
}
pub fn (b mut C.sg_bindings) set_vert_image(index int, img C.sg_image) {
pub fn (mut b C.sg_bindings) set_vert_image(index int, img C.sg_image) {
b.vs_images[index] = img
}
pub fn (b mut C.sg_bindings) set_frag_image(index int, img C.sg_image) {
pub fn (mut b C.sg_bindings) set_frag_image(index int, img C.sg_image) {
b.fs_images[index] = img
}
@ -96,45 +96,45 @@ pub mut:
_end_canary u32
}
pub fn (desc mut C.sg_shader_desc) set_vert_src(src string) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_vert_src(src string) &C.sg_shader_desc {
desc.vs.source = src.str
return desc
}
pub fn (desc mut C.sg_shader_desc) set_frag_src(src string) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_frag_src(src string) &C.sg_shader_desc {
desc.fs.source = src.str
return desc
}
pub fn (desc mut C.sg_shader_desc) set_vert_image(index int, name string) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_vert_image(index int, name string) &C.sg_shader_desc {
desc.vs.images[index].name = name.str
desc.vs.images[index].@type = ._2d
return desc
}
pub fn (desc mut C.sg_shader_desc) set_frag_image(index int, name string) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_frag_image(index int, name string) &C.sg_shader_desc {
desc.fs.images[index].name = name.str
desc.fs.images[index].@type = ._2d
return desc
}
pub fn (desc mut C.sg_shader_desc) set_vert_uniform_block_size(block_index, size int) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_vert_uniform_block_size(block_index, size int) &C.sg_shader_desc {
desc.vs.uniform_blocks[block_index].size = size
return desc
}
pub fn (desc mut C.sg_shader_desc) set_frag_uniform_block_size(block_index, size int) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_frag_uniform_block_size(block_index, size int) &C.sg_shader_desc {
desc.fs.uniform_blocks[block_index].size = size
return desc
}
pub fn (desc mut C.sg_shader_desc) set_vert_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_vert_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &C.sg_shader_desc {
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].name = name.str
desc.vs.uniform_blocks[block_index].uniforms[uniform_index].@type = @type
return desc
}
pub fn (desc mut C.sg_shader_desc) set_frag_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &C.sg_shader_desc {
pub fn (mut desc C.sg_shader_desc) set_frag_uniform(block_index int, uniform_index int, name string, @type UniformType, array_count int) &C.sg_shader_desc {
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].name = name.str
desc.fs.uniform_blocks[block_index].uniforms[uniform_index].@type = @type
return desc
@ -162,7 +162,7 @@ pub mut:
images [12]C.sg_shader_image_desc
}
pub fn (desc mut C.sg_shader_stage_desc) set_image(index int, name string) C.sg_shader_stage_desc {
pub fn (mut desc C.sg_shader_stage_desc) set_image(index int, name string) C.sg_shader_stage_desc {
desc.images[index].name = name.str
desc.images[index].@type = ._2d
return desc
@ -416,7 +416,7 @@ pub mut:
}
/*
pub fn (action mut C.sg_color_attachment_action) set_color_values(r, g, b, a f32) {
pub fn (mut action C.sg_color_attachment_action) set_color_values(r, g, b, a f32) {
action.val[0] = r
action.val[1] = g
action.val[2] = b

View File

@ -20,17 +20,17 @@ pub fn new_builder(initial_size int) Builder {
}
}
pub fn (b mut Builder) write_bytes(bytes byteptr, howmany int) {
pub fn (mut b Builder) write_bytes(bytes byteptr, howmany int) {
b.buf.push_many(bytes, howmany)
b.len += howmany
}
pub fn (b mut Builder) write_b(data byte) {
pub fn (mut b Builder) write_b(data byte) {
b.buf << data
b.len++
}
pub fn (b mut Builder) write(s string) {
pub fn (mut b Builder) write(s string) {
if s == '' {
return
}
@ -42,17 +42,17 @@ pub fn (b mut Builder) write(s string) {
b.len += s.len
}
pub fn (b mut Builder) go_back(n int) {
pub fn (mut b Builder) go_back(n int) {
b.buf.trim(b.buf.len-n)
b.len -= n
}
pub fn (b mut Builder) go_back_to(pos int) {
pub fn (mut b Builder) go_back_to(pos int) {
b.buf.trim(pos)
b.len = pos
}
pub fn (b mut Builder) writeln(s string) {
pub fn (mut b Builder) writeln(s string) {
// for c in s {
// b.buf << c
// }
@ -86,7 +86,7 @@ pub fn (b &Builder) after(n int) string {
// NB: in order to avoid memleaks and additional memory copies, after a call to b.str(),
// the builder b will be empty. The returned string *owns* the accumulated data so far.
pub fn (b mut Builder) str() string {
pub fn (mut b Builder) str() string {
b.str_calls++
if b.str_calls > 1 {
panic('builder.str() should be called just once.\n' +
@ -100,7 +100,7 @@ pub fn (b mut Builder) str() string {
return s
}
pub fn (b mut Builder) free() {
pub fn (mut b Builder) free() {
unsafe{
free(b.buf.data)
}

View File

@ -19,18 +19,18 @@ pub fn new_builder(initial_size int) Builder {
}
}
pub fn (b mut Builder) write_b(data byte) {
pub fn (mut b Builder) write_b(data byte) {
b.buf << data
b.len++
}
pub fn (b mut Builder) write(s string) {
pub fn (mut b Builder) write(s string) {
b.buf.push_many(s.str, s.len)
//b.buf << []byte(s) // TODO
b.len += s.len
}
pub fn (b mut Builder) writeln(s string) {
pub fn (mut b Builder) writeln(s string) {
b.buf.push_many(s.str, s.len)
//b.buf << []byte(s) // TODO
b.buf << `\n`
@ -41,11 +41,11 @@ pub fn (b Builder) str() string {
return string(b.buf, b.len)
}
pub fn (b mut Builder) cut(n int) {
pub fn (mut b Builder) cut(n int) {
b.len -= n
}
pub fn (b mut Builder) free() {
pub fn (mut b Builder) free() {
b.buf = make(0, b.initial_size, 1)
b.len = 0
}

View File

@ -86,7 +86,7 @@ pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor {
// set_max_jobs gives you the ability to override the number
// of jobs *after* the PoolProcessor had been created already.
pub fn (pool mut PoolProcessor) set_max_jobs(njobs int) {
pub fn (mut pool PoolProcessor) set_max_jobs(njobs int) {
pool.njobs = njobs
}
@ -99,11 +99,11 @@ pub fn (pool mut PoolProcessor) set_max_jobs(njobs int) {
// work_on_items returns *after* all threads finish.
// You can optionally call get_results after that.
// TODO: uncomment, when generics work again
//pub fn (pool mut PoolProcessor) work_on_items<T>(items []T) {
//pub fn (mut pool PoolProcessor) work_on_items<T>(items []T) {
// pool.work_on_pointers( items.pointers() )
//}
pub fn (pool mut PoolProcessor) work_on_pointers(items []voidptr) {
pub fn (mut pool PoolProcessor) work_on_pointers(items []voidptr) {
mut njobs := runtime.nr_jobs()
if pool.njobs > 0 {
njobs = pool.njobs
@ -186,7 +186,7 @@ pub fn (pool &PoolProcessor) get_int_item(idx int) int {
// set_shared_context - can be called during the setup so that you can
// provide a context that is shared between all worker threads, like
// common options/settings.
pub fn (pool mut PoolProcessor) set_shared_context(context voidptr) {
pub fn (mut pool PoolProcessor) set_shared_context(context voidptr) {
pool.shared_context = context
}
@ -201,7 +201,7 @@ pub fn (pool &PoolProcessor) get_shared_context() voidptr {
// local storage area where it can write/read information that is private
// to the given thread, without worrying that it will get overwritten by
// another thread
pub fn (pool mut PoolProcessor) set_thread_context(idx int, context voidptr) {
pub fn (mut pool PoolProcessor) set_thread_context(idx int, context voidptr) {
pool.thread_contexts[idx] = context
}
@ -223,11 +223,11 @@ pub:
//
pub fn (pool mut PoolProcessor) work_on_items_s(items []string) {
pub fn (mut pool PoolProcessor) work_on_items_s(items []string) {
pool.work_on_pointers( items.pointers() )
}
pub fn (pool mut PoolProcessor) work_on_items_i(items []int) {
pub fn (mut pool PoolProcessor) work_on_items_i(items []int) {
pool.work_on_pointers( items.pointers() )
}

View File

@ -15,11 +15,10 @@ pub fn new_mutex() &Mutex {
return m
}
pub fn (m mut Mutex) lock() {
pub fn (mut m Mutex) lock() {
C.pthread_mutex_lock(&m.mutex)
}
pub fn (m mut Mutex) unlock() {
pub fn (mut m Mutex) unlock() {
C.pthread_mutex_unlock(&m.mutex)
}

View File

@ -41,7 +41,7 @@ pub fn new_mutex() &Mutex {
return sm
}
pub fn (m mut Mutex) lock() {
pub fn (mut m Mutex) lock() {
// if mutex handle not initalized
if isnil(m.mx) {
m.mx = C.CreateMutex(0, false, 0)
@ -68,7 +68,7 @@ pub fn (m mut Mutex) lock() {
}
}
pub fn (m mut Mutex) unlock() {
pub fn (mut m Mutex) unlock() {
if m.state == .waiting {
if C.ReleaseMutex(m.mx) {
m.state = .broken
@ -78,7 +78,7 @@ pub fn (m mut Mutex) unlock() {
m.state = .released
}
pub fn (m mut Mutex) destroy() {
pub fn (mut m Mutex) destroy() {
if m.state == .waiting {
m.unlock() // unlock mutex before destroying
}

View File

@ -15,7 +15,7 @@ pub fn new_waitgroup() &WaitGroup {
return &WaitGroup{mu: sync.new_mutex() }
}
pub fn (wg mut WaitGroup) add(delta int) {
pub fn (mut wg WaitGroup) add(delta int) {
wg.mu.lock()
wg.active += delta
wg.mu.unlock()
@ -24,7 +24,7 @@ pub fn (wg mut WaitGroup) add(delta int) {
}
}
pub fn (wg mut WaitGroup) done() {
pub fn (mut wg WaitGroup) done() {
wg.add(-1)
}
@ -39,4 +39,3 @@ pub fn (wg &WaitGroup) wait() {
}
}
}

View File

@ -66,7 +66,7 @@ pub fn open(name string, level int, mode string) ?zip_ptr {
*
* @param zip zip archive handler.
*/
pub fn (z mut zip_ptr) close() {
pub fn (mut z zip_ptr) close() {
C.zip_close(z)
}
@ -82,7 +82,7 @@ pub fn (z mut zip_ptr) close() {
*
* @return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (zentry mut zip_ptr) open_entry(name string) /*?*/bool {
pub fn (mut zentry zip_ptr) open_entry(name string) /*?*/bool {
res := C.zip_entry_open(zentry, name.str)
return res != -1
}
@ -94,7 +94,7 @@ pub fn (zentry mut zip_ptr) open_entry(name string) /*?*/bool {
*
* @return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (zentry mut zip_ptr) close_entry() {
pub fn (mut zentry zip_ptr) close_entry() {
C.zip_entry_close(zentry)
}
@ -112,7 +112,7 @@ pub fn (zentry mut zip_ptr) close_entry() {
*
* @return the pointer to the current zip entry name, or NULL on error.
*/
pub fn (zentry mut zip_ptr) name() string {
pub fn (mut zentry zip_ptr) name() string {
_name := C.zip_entry_name(zentry)
if _name == 0 {
return ''
@ -127,7 +127,7 @@ pub fn (zentry mut zip_ptr) name() string {
*
* @return the index on success, negative number (< 0) on error.
*/
pub fn (zentry mut zip_ptr) index() ?int {
pub fn (mut zentry zip_ptr) index() ?int {
_index := int(C.zip_entry_index(zentry))
if _index == -1 {
return error('szip: cannot get current index of zip entry')
@ -143,7 +143,7 @@ pub fn (zentry mut zip_ptr) index() ?int {
* @return the return code - 1 (true), 0 (false), negative number (< 0) on
* error.
*/
pub fn (zentry mut zip_ptr) isdir() ?bool {
pub fn (mut zentry zip_ptr) isdir() ?bool {
_isdir := C.zip_entry_isdir(zentry)
if _isdir == -1 {
return error('szip: cannot check entry type')
@ -159,7 +159,7 @@ pub fn (zentry mut zip_ptr) isdir() ?bool {
*
* @return the uncompressed size in bytes.
*/
pub fn (zentry mut zip_ptr) size() i64 {
pub fn (mut zentry zip_ptr) size() i64 {
_size := i64(C.zip_entry_size(zentry))
return _size
}
@ -171,7 +171,7 @@ pub fn (zentry mut zip_ptr) size() i64 {
*
* @return the CRC-32 checksum.
*/
pub fn (zentry mut zip_ptr) crc32() u32 {
pub fn (mut zentry zip_ptr) crc32() u32 {
_checksum := u32(C.zip_entry_crc32(zentry))
return _checksum // 0
}
@ -185,7 +185,7 @@ pub fn (zentry mut zip_ptr) crc32() u32 {
*
* @return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (zentry mut zip_ptr) write_entry(data []byte) bool {
pub fn (mut zentry zip_ptr) write_entry(data []byte) bool {
if (data[0] & 0xff) == -1 {
return false
}
@ -202,7 +202,7 @@ pub fn (zentry mut zip_ptr) write_entry(data []byte) bool {
*
* @return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (zentry mut zip_ptr) create_entry(name string) bool {
pub fn (mut zentry zip_ptr) create_entry(name string) bool {
res := C.zip_entry_fwrite(zentry, name.str)
return res == 0
}
@ -222,7 +222,7 @@ pub fn (zentry mut zip_ptr) create_entry(name string) bool {
* @return the return code - the number of bytes actually read on success.
* Otherwise a -1 on error.
*/
pub fn (zentry mut zip_ptr) read_entry() ?voidptr {
pub fn (mut zentry zip_ptr) read_entry() ?voidptr {
mut _buf := voidptr(0)
mut _bsize := i64(0)
res := C.zip_entry_read(zentry, &_buf, &_bsize)
@ -240,7 +240,7 @@ pub fn (zentry mut zip_ptr) read_entry() ?voidptr {
*
* @return the return code - 0 on success, negative number (< 0) on error.
*/
pub fn (zentry mut zip_ptr) extract_entry(path string) /*?*/bool {
pub fn (mut zentry zip_ptr) extract_entry(path string) /*?*/bool {
if C.access(path.str, 0) == -1 {
return false
//return error('Cannot open file for extracting, file not exists')
@ -259,7 +259,7 @@ pub fn (zentry mut zip_ptr) extract_entry(path string) /*?*/bool {
*
* @return the return code - 0 on success, negative number (< 0) on error.
*/
/*fn (zentry mut zip_ptr) extract(path string) bool {
/*fn (mut zentry zip_ptr) extract(path string) bool {
if C.access(path.str, 0) == -1 {
return false
//return error('Cannot open directory for extracting, directory not exists')
@ -276,7 +276,7 @@ pub fn (zentry mut zip_ptr) extract_entry(path string) /*?*/bool {
* @return the return code - the number of entries on success, negative number
* (< 0) on error.
*/
pub fn (zentry mut zip_ptr) total() ?int {
pub fn (mut zentry zip_ptr) total() ?int {
_tentry := int(C.zip_total_entries(zentry))
if _tentry == -1 {
return error('szip: cannot count total entries')

View File

@ -16,7 +16,7 @@ pub fn new_stopwatch() StopWatch {
}
// start Starts the timer. If the timer was paused, restarts counting.
pub fn (t mut StopWatch) start() {
pub fn (mut t StopWatch) start() {
if t.pause_time == 0 {
t.start = time.sys_mono_now()
} else {
@ -26,18 +26,18 @@ pub fn (t mut StopWatch) start() {
t.pause_time = 0
}
pub fn (t mut StopWatch) restart() {
pub fn (mut t StopWatch) restart() {
t.end = 0
t.pause_time = 0
t.start = time.sys_mono_now()
}
pub fn (t mut StopWatch) stop() {
pub fn (mut t StopWatch) stop() {
t.end = time.sys_mono_now()
t.pause_time = 0
}
pub fn (t mut StopWatch) pause() {
pub fn (mut t StopWatch) pause() {
t.pause_time = time.sys_mono_now()
t.end = t.pause_time // so elapsed keeps track of actual running time
}
@ -50,4 +50,3 @@ pub fn (t StopWatch) elapsed() Duration {
return Duration(t.end - t.start)
}
}

View File

@ -88,7 +88,7 @@ pub fn (s &Scope) known_var(name string) bool {
return false
}
pub fn (s mut Scope) update_var_type(name string, typ table.Type) {
pub fn (mut s Scope) update_var_type(name string, typ table.Type) {
match mut s.objects[name] {
Var {
if it.typ == typ {
@ -100,7 +100,7 @@ pub fn (s mut Scope) update_var_type(name string, typ table.Type) {
}
}
pub fn (s mut Scope) register(name string, obj ScopeObject) {
pub fn (mut s Scope) register(name string, obj ScopeObject) {
if name == '_' {
return
}

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/mut_receiver_warning.v:5:7: warning: use `(mut f Foo)` instead of `(f mut Foo)`
3 | name string
4 | }
5 | fn (f mut Foo) info() {
| ~~~
6 | f.name = 'foo'
7 | }

View File

@ -0,0 +1,10 @@
struct Foo{
mut:
name string
}
fn (f mut Foo) info() {
f.name = 'foo'
}
fn main() {
println('hello, world')
}

View File

@ -91,7 +91,7 @@ pub fn gen(files []ast.File, table &table.Table, pref &pref.Preferences) string
return out
}
pub fn (g mut JsGen) enter_namespace(n string) {
pub fn (mut g JsGen) enter_namespace(n string) {
g.namespace = n
if g.namespaces[g.namespace].len == 0 {
// create a new namespace
@ -104,16 +104,16 @@ pub fn (g mut JsGen) enter_namespace(n string) {
}
}
pub fn (g mut JsGen) escape_namespace() {
pub fn (mut g JsGen) escape_namespace() {
g.namespaces[g.namespace] = g.out
g.namespace = ""
}
pub fn (g mut JsGen) push_pub_var(s string) {
pub fn (mut g JsGen) push_pub_var(s string) {
g.namespaces_pub[g.namespace] << s
}
pub fn (g mut JsGen) find_class_methods(stmts []ast.Stmt) {
pub fn (mut g JsGen) find_class_methods(stmts []ast.Stmt) {
for stmt in stmts {
match stmt {
ast.FnDecl {
@ -131,13 +131,13 @@ pub fn (g mut JsGen) find_class_methods(stmts []ast.Stmt) {
}
}
pub fn (g mut JsGen) init() {
pub fn (mut g JsGen) init() {
g.definitions.writeln('// Generated by the V compiler')
g.definitions.writeln('"use strict";')
g.definitions.writeln('')
}
pub fn (g mut JsGen) finish() {
pub fn (mut g JsGen) finish() {
if g.constants.len > 0 {
constants := g.constants.str()
g.constants = strings.new_builder(100)
@ -156,7 +156,7 @@ pub fn (g JsGen) hashes() string {
// V type to JS type
pub fn (g mut JsGen) typ(t table.Type) string {
pub fn (mut g JsGen) typ(t table.Type) string {
sym := g.table.get_type_symbol(t)
mut styp := sym.name.replace('.', '__')
if styp.starts_with('JS__') {
@ -165,7 +165,7 @@ pub fn (g mut JsGen) typ(t table.Type) string {
return g.to_js_typ(styp)
}
fn (g mut JsGen) to_js_typ(typ string) string {
fn (mut g JsGen) to_js_typ(typ string) string {
mut styp := ''
match typ {
'int' {
@ -199,33 +199,33 @@ fn (g mut JsGen) to_js_typ(typ string) string {
pub fn (g &JsGen) save() {}
pub fn (g mut JsGen) gen_indent() {
pub fn (mut g JsGen) gen_indent() {
if g.indents[g.namespace] > 0 && g.empty_line {
g.out.write(tabs[g.indents[g.namespace]])
}
g.empty_line = false
}
pub fn (g mut JsGen) inc_indent() {
pub fn (mut g JsGen) inc_indent() {
g.indents[g.namespace]++
}
pub fn (g mut JsGen) dec_indent() {
pub fn (mut g JsGen) dec_indent() {
g.indents[g.namespace]--
}
pub fn (g mut JsGen) write(s string) {
pub fn (mut g JsGen) write(s string) {
g.gen_indent()
g.out.write(s)
}
pub fn (g mut JsGen) writeln(s string) {
pub fn (mut g JsGen) writeln(s string) {
g.gen_indent()
g.out.writeln(s)
g.empty_line = true
}
pub fn (g mut JsGen) new_tmp_var() string {
pub fn (mut g JsGen) new_tmp_var() string {
g.tmp_count++
return '_tmp$g.tmp_count'
}
@ -239,7 +239,7 @@ fn js_name(name string) string {
return name
}
fn (g mut JsGen) stmts(stmts []ast.Stmt) {
fn (mut g JsGen) stmts(stmts []ast.Stmt) {
g.inc_indent()
for stmt in stmts {
g.stmt(stmt)
@ -247,7 +247,7 @@ fn (g mut JsGen) stmts(stmts []ast.Stmt) {
g.dec_indent()
}
fn (g mut JsGen) stmt(node ast.Stmt) {
fn (mut g JsGen) stmt(node ast.Stmt) {
g.stmt_start_pos = g.out.len
match node {
@ -341,7 +341,7 @@ fn (g mut JsGen) stmt(node ast.Stmt) {
}
}
fn (g mut JsGen) expr(node ast.Expr) {
fn (mut g JsGen) expr(node ast.Expr) {
match node {
ast.ArrayInit {
g.gen_array_init_expr(it)
@ -436,7 +436,7 @@ fn (g mut JsGen) expr(node ast.Expr) {
}
}
fn (g mut JsGen) gen_string_inter_literal(it ast.StringInterLiteral) {
fn (mut g JsGen) gen_string_inter_literal(it ast.StringInterLiteral) {
g.write('tos3(`')
for i, val in it.vals {
escaped_val := val.replace_each(['`', '\`', '\r\n', '\n'])
@ -483,7 +483,7 @@ fn (g mut JsGen) gen_string_inter_literal(it ast.StringInterLiteral) {
g.write('`)')
}
fn (g mut JsGen) gen_array_init_expr(it ast.ArrayInit) {
fn (mut g JsGen) gen_array_init_expr(it ast.ArrayInit) {
type_sym := g.table.get_type_symbol(it.typ)
if type_sym.kind != .array_fixed {
g.write('[')
@ -497,7 +497,7 @@ fn (g mut JsGen) gen_array_init_expr(it ast.ArrayInit) {
} else {}
}
fn (g mut JsGen) gen_assert_stmt(a ast.AssertStmt) {
fn (mut g JsGen) gen_assert_stmt(a ast.AssertStmt) {
g.writeln('// assert')
g.write('if( ')
g.expr(a.expr)
@ -520,7 +520,7 @@ fn (g mut JsGen) gen_assert_stmt(a ast.AssertStmt) {
g.writeln('}')
}
fn (g mut JsGen) gen_assign_stmt(it ast.AssignStmt) {
fn (mut g JsGen) gen_assign_stmt(it ast.AssignStmt) {
if it.left.len > it.right.len {
// multi return
jsdoc := strings.new_builder(50)
@ -586,23 +586,23 @@ fn (g mut JsGen) gen_assign_stmt(it ast.AssignStmt) {
}
}
fn (g mut JsGen) gen_attr(it ast.Attr) {
fn (mut g JsGen) gen_attr(it ast.Attr) {
g.writeln('/* [$it.name] */')
}
fn (g mut JsGen) gen_block(it ast.Block) {
fn (mut g JsGen) gen_block(it ast.Block) {
g.writeln('{')
g.stmts(it.stmts)
g.writeln('}')
}
fn (g mut JsGen) gen_branch_stmt(it ast.BranchStmt) {
fn (mut g JsGen) gen_branch_stmt(it ast.BranchStmt) {
// continue or break
g.write(it.tok.kind.str())
g.writeln(';')
}
fn (g mut JsGen) gen_const_decl(it ast.ConstDecl) {
fn (mut g JsGen) gen_const_decl(it ast.ConstDecl) {
// old_indent := g.indents[g.namespace]
for i, field in it.fields {
// TODO hack. Cut the generated value and paste it into definitions.
@ -622,7 +622,7 @@ fn (g mut JsGen) gen_const_decl(it ast.ConstDecl) {
g.constants.writeln('')
}
fn (g mut JsGen) gen_defer_stmts() {
fn (mut g JsGen) gen_defer_stmts() {
g.writeln('(function defer() {')
for defer_stmt in g.defer_stmts {
g.stmts(defer_stmt.stmts)
@ -630,7 +630,7 @@ fn (g mut JsGen) gen_defer_stmts() {
g.writeln('})();')
}
fn (g mut JsGen) gen_enum_decl(it ast.EnumDecl) {
fn (mut g JsGen) gen_enum_decl(it ast.EnumDecl) {
g.writeln('const ${js_name(it.name)} = Object.freeze({')
g.inc_indent()
for i, field in it.fields {
@ -653,7 +653,7 @@ fn (g mut JsGen) gen_enum_decl(it ast.EnumDecl) {
}
}
fn (g mut JsGen) gen_expr_stmt(it ast.ExprStmt) {
fn (mut g JsGen) gen_expr_stmt(it ast.ExprStmt) {
g.expr(it.expr)
expr := it.expr
match expr {
@ -668,7 +668,7 @@ fn (g mut JsGen) gen_expr_stmt(it ast.ExprStmt) {
}
}
fn (g mut JsGen) gen_fn_decl(it ast.FnDecl) {
fn (mut g JsGen) gen_fn_decl(it ast.FnDecl) {
if it.is_method {
// Struct methods are handled by class generation code.
return
@ -679,7 +679,7 @@ fn (g mut JsGen) gen_fn_decl(it ast.FnDecl) {
g.gen_method_decl(it)
}
fn (g mut JsGen) gen_method_decl(it ast.FnDecl) {
fn (mut g JsGen) gen_method_decl(it ast.FnDecl) {
g.fn_decl = &it
has_go := fn_has_go(it)
is_main := it.name == 'main'
@ -739,7 +739,7 @@ fn (g mut JsGen) gen_method_decl(it ast.FnDecl) {
g.fn_decl = 0
}
fn (g mut JsGen) gen_for_c_stmt(it ast.ForCStmt) {
fn (mut g JsGen) gen_for_c_stmt(it ast.ForCStmt) {
g.inside_loop = true
g.write('for (')
if it.has_init {
@ -760,7 +760,7 @@ fn (g mut JsGen) gen_for_c_stmt(it ast.ForCStmt) {
g.inside_loop = false
}
fn (g mut JsGen) gen_for_in_stmt(it ast.ForInStmt) {
fn (mut g JsGen) gen_for_in_stmt(it ast.ForInStmt) {
if it.is_range {
// `for x in 1..10 {`
i := it.val_var
@ -813,7 +813,7 @@ fn (g mut JsGen) gen_for_in_stmt(it ast.ForInStmt) {
}
}
fn (g mut JsGen) gen_for_stmt(it ast.ForStmt) {
fn (mut g JsGen) gen_for_stmt(it ast.ForStmt) {
g.write('while (')
if it.is_inf {
g.write('true')
@ -825,7 +825,7 @@ fn (g mut JsGen) gen_for_stmt(it ast.ForStmt) {
g.writeln('}')
}
fn (g mut JsGen) fn_args(args []table.Arg, is_variadic bool) {
fn (mut g JsGen) fn_args(args []table.Arg, is_variadic bool) {
// no_names := args.len > 0 && args[0].name == 'arg_1'
for i, arg in args {
name := js_name(arg.name)
@ -842,7 +842,7 @@ fn (g mut JsGen) fn_args(args []table.Arg, is_variadic bool) {
}
}
fn (g mut JsGen) gen_go_stmt(node ast.GoStmt) {
fn (mut g JsGen) gen_go_stmt(node ast.GoStmt) {
// x := node.call_expr as ast.CallEpxr // TODO
match node.call_expr {
ast.CallExpr {
@ -869,7 +869,7 @@ fn (g mut JsGen) gen_go_stmt(node ast.GoStmt) {
}
}
fn (g mut JsGen) gen_map_init_expr(it ast.MapInit) {
fn (mut g JsGen) gen_map_init_expr(it ast.MapInit) {
// key_typ_sym := g.table.get_type_symbol(it.key_type)
// value_typ_sym := g.table.get_type_symbol(it.value_type)
// key_typ_str := key_typ_sym.name.replace('.', '__')
@ -896,7 +896,7 @@ fn (g mut JsGen) gen_map_init_expr(it ast.MapInit) {
}
}
fn (g mut JsGen) gen_return_stmt(it ast.Return) {
fn (mut g JsGen) gen_return_stmt(it ast.Return) {
g.write('return ')
if g.fn_decl.name == 'main' {
@ -922,7 +922,7 @@ fn (g mut JsGen) gen_return_stmt(it ast.Return) {
g.writeln(';')
}
fn (g mut JsGen) enum_expr(node ast.Expr) {
fn (mut g JsGen) enum_expr(node ast.Expr) {
match node {
ast.EnumVal {
g.write(it.val)
@ -933,7 +933,7 @@ fn (g mut JsGen) enum_expr(node ast.Expr) {
}
}
fn (g mut JsGen) gen_struct_decl(node ast.StructDecl) {
fn (mut g JsGen) gen_struct_decl(node ast.StructDecl) {
g.writeln('class ${js_name(node.name)} {')
g.inc_indent()
g.writeln(g.doc.gen_ctor(node.fields))
@ -968,7 +968,7 @@ fn (g mut JsGen) gen_struct_decl(node ast.StructDecl) {
}
}
fn (g mut JsGen) gen_struct_init(it ast.StructInit) {
fn (mut g JsGen) gen_struct_init(it ast.StructInit) {
type_sym := g.table.get_type_symbol(it.typ)
g.writeln('new ${type_sym.name}({')
g.inc_indent()
@ -984,7 +984,7 @@ fn (g mut JsGen) gen_struct_init(it ast.StructInit) {
g.write('})')
}
fn (g mut JsGen) gen_ident(node ast.Ident) {
fn (mut g JsGen) gen_ident(node ast.Ident) {
if node.kind == .constant {
g.write('CONSTANTS.')
}
@ -996,12 +996,12 @@ fn (g mut JsGen) gen_ident(node ast.Ident) {
g.write(name)
}
fn (g mut JsGen) gen_selector_expr(it ast.SelectorExpr) {
fn (mut g JsGen) gen_selector_expr(it ast.SelectorExpr) {
g.expr(it.expr)
g.write('.$it.field_name')
}
fn (g mut JsGen) gen_if_expr(node ast.IfExpr) {
fn (mut g JsGen) gen_if_expr(node ast.IfExpr) {
type_sym := g.table.get_type_symbol(node.typ)
// one line ?:

View File

@ -134,6 +134,9 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
rec_name = p.check_name()
if !rec_mut {
rec_mut = p.tok.kind == .key_mut
if rec_mut {
p.warn_with_pos('use `(mut f Foo)` instead of `(f mut Foo)`', p.tok.position())
}
}
receiver_pos = rec_start_pos.extend(p.tok.position())
is_amp := p.tok.kind == .amp

View File

@ -28,7 +28,7 @@ fn (mut p Parser) register_used_import(alias string) {
}
}
fn (p mut Parser) check_unused_imports() {
fn (mut p Parser) check_unused_imports() {
mut output := ''
for alias, mod in p.imports {
if !p.is_used_import(alias) {

View File

@ -85,7 +85,7 @@ fn (s &Scanner) new_token(tok_kind token.Kind, lit string, len int) token.Token
}
}
fn (s mut Scanner) ident_name() string {
fn (mut s Scanner) ident_name() string {
start := s.pos
s.pos++
for s.pos < s.text.len && (util.is_name_char(s.text[s.pos]) || s.text[s.pos].is_digit()) {
@ -97,7 +97,7 @@ fn (s mut Scanner) ident_name() string {
}
// ident_fn_name look ahead and return name of function if possible, otherwise empty string
fn (s mut Scanner) ident_fn_name() string {
fn (mut s Scanner) ident_fn_name() string {
start := s.pos
mut pos := s.pos
pos++
@ -155,7 +155,7 @@ fn filter_num_sep(txt byteptr, start int, end int) string {
}
}
fn (s mut Scanner) ident_bin_number() string {
fn (mut s Scanner) ident_bin_number() string {
mut has_wrong_digit := false
mut first_wrong_digit := `\0`
start_pos := s.pos
@ -184,7 +184,7 @@ fn (s mut Scanner) ident_bin_number() string {
return number
}
fn (s mut Scanner) ident_hex_number() string {
fn (mut s Scanner) ident_hex_number() string {
mut has_wrong_digit := false
mut first_wrong_digit := `\0`
start_pos := s.pos
@ -213,7 +213,7 @@ fn (s mut Scanner) ident_hex_number() string {
return number
}
fn (s mut Scanner) ident_oct_number() string {
fn (mut s Scanner) ident_oct_number() string {
mut has_wrong_digit := false
mut first_wrong_digit := `\0`
start_pos := s.pos
@ -242,7 +242,7 @@ fn (s mut Scanner) ident_oct_number() string {
return number
}
fn (s mut Scanner) ident_dec_number() string {
fn (mut s Scanner) ident_dec_number() string {
mut has_wrong_digit := false
mut first_wrong_digit := `\0`
start_pos := s.pos
@ -355,7 +355,7 @@ fn (s mut Scanner) ident_dec_number() string {
return number
}
fn (s mut Scanner) ident_number() string {
fn (mut s Scanner) ident_number() string {
if s.expect('0b', s.pos) {
return s.ident_bin_number()
}
@ -370,7 +370,7 @@ fn (s mut Scanner) ident_number() string {
}
}
fn (s mut Scanner) skip_whitespace() {
fn (mut s Scanner) skip_whitespace() {
// if s.is_vh { println('vh') return }
for s.pos < s.text.len && s.text[s.pos].is_space() {
if util.is_nl(s.text[s.pos]) && s.is_vh {
@ -384,13 +384,13 @@ fn (s mut Scanner) skip_whitespace() {
}
}
fn (s mut Scanner) end_of_file() token.Token {
fn (mut s Scanner) end_of_file() token.Token {
s.pos = s.text.len
s.inc_line_number()
return s.new_token(.eof, '', 1)
}
pub fn (s mut Scanner) scan() token.Token {
pub fn (mut s Scanner) scan() token.Token {
// if s.comments_mode == .parse_comments {
// println('\nscan()')
// }
@ -868,7 +868,7 @@ fn (s &Scanner) count_symbol_before(p int, sym byte) int {
return count
}
fn (s mut Scanner) ident_string() string {
fn (mut s Scanner) ident_string() string {
q := s.text[s.pos]
is_quote := q == single_quote || q == double_quote
is_raw := is_quote && s.pos > 0 && s.text[s.pos - 1] == `r`
@ -956,7 +956,7 @@ fn trim_slash_line_break(s string) string {
return ret_str
}
fn (s mut Scanner) ident_char() string {
fn (mut s Scanner) ident_char() string {
start := s.pos
slash := `\\`
mut len := 0
@ -1005,7 +1005,7 @@ fn (s &Scanner) expect(want string, start_pos int) bool {
return true
}
fn (s mut Scanner) debug_tokens() {
fn (mut s Scanner) debug_tokens() {
s.pos = 0
s.is_started = false
s.is_debug = true
@ -1029,18 +1029,18 @@ fn (s mut Scanner) debug_tokens() {
}
}
fn (s mut Scanner) ignore_line() {
fn (mut s Scanner) ignore_line() {
s.eat_to_end_of_line()
s.inc_line_number()
}
fn (s mut Scanner) eat_to_end_of_line() {
fn (mut s Scanner) eat_to_end_of_line() {
for s.pos < s.text.len && s.text[s.pos] != `\n` {
s.pos++
}
}
fn (s mut Scanner) inc_line_number() {
fn (mut s Scanner) inc_line_number() {
s.last_nl_pos = s.pos
s.line_nr++
s.line_ends << s.pos

View File

@ -74,7 +74,7 @@ mut:
y f64
}
fn (p mut Point) translate<T>(x, y T) {
fn (mut p Point) translate<T>(x, y T) {
p.x += x
p.y += y
}

View File

@ -19,7 +19,7 @@ fn new_room() &ChatRoom {
}
}
fn (r mut ChatRoom) add(name string, s Speaker) {
fn (mut r ChatRoom) add(name string, s Speaker) {
r.talkers[name] = s
}

View File

@ -58,7 +58,7 @@ pub fn (mcache &ModFileCacher) dump() {
}
}
pub fn (mcache mut ModFileCacher) get(mfolder string) ModFileAndFolder {
pub fn (mut mcache ModFileCacher) get(mfolder string) ModFileAndFolder {
if mfolder in mcache.cache {
return mcache.cache[ mfolder ]
}
@ -69,11 +69,11 @@ pub fn (mcache mut ModFileCacher) get(mfolder string) ModFileAndFolder {
return res
}
fn (cacher mut ModFileCacher) add(path string, result ModFileAndFolder) {
fn (mut cacher ModFileCacher) add(path string, result ModFileAndFolder) {
cacher.cache[ path ] = result
}
fn (mcache mut ModFileCacher) traverse(mfolder string) ([]string, ModFileAndFolder) {
fn (mut mcache ModFileCacher) traverse(mfolder string) ([]string, ModFileAndFolder) {
mut cfolder := mfolder
mut folders_so_far := [cfolder]
mut levels := 0
@ -111,13 +111,13 @@ fn (mcache mut ModFileCacher) traverse(mfolder string) ([]string, ModFileAndFold
return [mfolder], ModFileAndFolder{ vmod_file: '', vmod_folder: mfolder }
}
fn (mcache mut ModFileCacher) mark_folders_with_vmod( folders_so_far []string, vmod ModFileAndFolder ) {
fn (mut mcache ModFileCacher) mark_folders_with_vmod( folders_so_far []string, vmod ModFileAndFolder ) {
for f in folders_so_far {
mcache.add( f, vmod )
}
}
fn (mcache mut ModFileCacher) mark_folders_as_vmod_free( folders_so_far []string ) {
fn (mut mcache ModFileCacher) mark_folders_as_vmod_free( folders_so_far []string ) {
// No need to check these folders anymore,
// because their parents do not contain v.mod files
for f in folders_so_far {
@ -135,7 +135,7 @@ fn (mcache &ModFileCacher) check_for_stop(cfolder string, files []string) bool {
return false
}
fn (mcache mut ModFileCacher) get_files(cfolder string) []string {
fn (mut mcache ModFileCacher) get_files(cfolder string) []string {
if cfolder in mcache.folder_files {
return mcache.folder_files[ cfolder ]
}

View File

@ -33,12 +33,12 @@ pub fn new_manager() &AssetManager {
}
// add_css adds a css asset
pub fn (am mut AssetManager) add_css(file string) bool {
pub fn (mut am AssetManager) add_css(file string) bool {
return am.add('css', file)
}
// add_js adds a js asset
pub fn (am mut AssetManager) add_js(file string) bool {
pub fn (mut am AssetManager) add_js(file string) bool {
return am.add('js', file)
}
@ -149,8 +149,8 @@ fn (am AssetManager) include(asset_type string, combine bool) string {
}
// dont return option until size limit is removed
// fn (am mut AssetManager) add(asset_type, file string) ?bool {
fn (am mut AssetManager) add(asset_type, file string) bool {
// fn (mut am AssetManager) add(asset_type, file string) ?bool {
fn (mut am AssetManager) add(asset_type, file string) bool {
if !os.exists(file) {
// return error('vweb.assets: cannot add asset $file, it does not exist')
return false

View File

@ -48,7 +48,7 @@ mut:
done bool
}
fn (ctx mut Context) send_response_to_client(mimetype string, res string) bool {
fn (mut ctx Context) send_response_to_client(mimetype string, res string) bool {
if ctx.done { return false }
ctx.done = true
mut sb := strings.new_builder(1024)
@ -63,31 +63,31 @@ fn (ctx mut Context) send_response_to_client(mimetype string, res string) bool {
return true
}
pub fn (ctx mut Context) html(s string) {
pub fn (mut ctx Context) html(s string) {
ctx.send_response_to_client('text/html', s)
}
pub fn (ctx mut Context) text(s string) {
pub fn (mut ctx Context) text(s string) {
ctx.send_response_to_client('text/plain', s)
}
pub fn (ctx mut Context) json(s string) {
pub fn (mut ctx Context) json(s string) {
ctx.send_response_to_client('application/json', s)
}
pub fn (ctx mut Context) redirect(url string) {
pub fn (mut ctx Context) redirect(url string) {
if ctx.done { return }
ctx.done = true
ctx.conn.send_string('HTTP/1.1 302 Found\r\nLocation: ${url}${ctx.headers}\r\n${HEADERS_CLOSE}') or { return }
}
pub fn (ctx mut Context) not_found(s string) {
pub fn (mut ctx Context) not_found(s string) {
if ctx.done { return }
ctx.done = true
ctx.conn.send_string(HTTP_404) or { return }
}
pub fn (ctx mut Context) set_cookie(key, val string) {
pub fn (mut ctx Context) set_cookie(key, val string) {
// TODO support directives, escape cookie value (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)
//println('Set-Cookie $key=$val')
ctx.add_header('Set-Cookie', '${key}=${val}; Secure; HttpOnly')
@ -112,7 +112,7 @@ pub fn (ctx &Context) get_cookie(key string) ?string { // TODO refactor
return error('Cookie not found')
}
pub fn (ctx mut Context) add_header(key, val string) {
pub fn (mut ctx Context) add_header(key, val string) {
//println('add_header($key, $val)')
ctx.headers = ctx.headers + '\r\n$key: $val'
//println(ctx.headers)
@ -290,7 +290,7 @@ fn handle_conn<T>(conn net.Socket, app mut T) {
app.reset()
}
fn (ctx mut Context) parse_form(s string) {
fn (mut ctx Context) parse_form(s string) {
if ctx.req.method !in methods_with_form {
return
}
@ -319,7 +319,7 @@ fn (ctx mut Context) parse_form(s string) {
// ...
}
fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) {
fn (mut ctx Context) scan_static_directory(directory_path, mount_path string) {
files := os.ls(directory_path) or { panic(err) }
if files.len > 0 {
@ -340,7 +340,7 @@ fn (ctx mut Context) scan_static_directory(directory_path, mount_path string) {
}
}
pub fn (ctx mut Context) handle_static(directory_path string) bool {
pub fn (mut ctx Context) handle_static(directory_path string) bool {
if ctx.done || ! os.exists(directory_path) {
return false
}
@ -358,7 +358,7 @@ pub fn (ctx mut Context) handle_static(directory_path string) bool {
return true
}
pub fn (ctx mut Context) serve_static(url, file_path, mime_type string) {
pub fn (mut ctx Context) serve_static(url, file_path, mime_type string) {
ctx.static_files[url] = file_path
ctx.static_mime_types[url] = mime_type
}