Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error translating from pure v to c #23525

Closed
venomega opened this issue Jan 19, 2025 · 2 comments
Closed

error translating from pure v to c #23525

venomega opened this issue Jan 19, 2025 · 2 comments

Comments

@venomega
Copy link

venomega commented Jan 19, 2025

V version: V 0.4.9 2aa5651, press to see full `v doctor` output
V full version V 0.4.9 d313355.2aa5651
OS linux, "Arch Linux"
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) 7 150U
Memory 7.66GB/15.31GB
V executable /opt/v/v
V last modified time 2025-01-06 10:27:48
V home dir OK, value: /opt/v
VMODULES OK, value: /home/venomega/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/venomega/vsync/src
Git version git version 2.47.1
V git status Error: fatal: bad revision 'HEAD'
.git/config present true
cc version cc (GCC) 14.2.1 20240910
gcc version gcc (GCC) 14.2.1 20240910
clang version clang version 18.1.8
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status N/A
emcc version N/A
glibc version ldd (GNU libc) 2.40

What did you do?
./v -g -o vdbg cmd/v && ./vdbg main.v && main

module main

import os
import math
import prantlf.cargs { parse, Input }

// Declare a structure with all command-line options.
struct Opts {
  output string
  indent int
  pretty bool
}

// Describe usage of the command-line tool.
fn parsero() ! (&Opts, []string) {

usage := 'Converts YAML input to JSON output.

Usage: yaml2json [options] [<yaml-file>]

  <yaml-file>         read the YAML input from a file

Options:
  -o|--output <file>   write the JSON output to a file
  -i|--indent <count>  write the JSON output to a file
  -p|--pretty          print the JSON output with line breaks and indented
  -V|--version         print the version of the executable and exit
  -h|--help            print the usage information and exit

If no input file is specified, it will be read from standard input.

Examples:
  $ yaml2json config.yaml -o config.json -p
  $ cat config.yaml | yaml2json > config.json'


// Parse command-line options and arguments.
opts, args := parse[Opts](usage, Input{ version: '0.0.1' })!
//return opts, args
return opts, args
}

fn main(){
	_, args := parsero()!
	if args.len != 2 {
		logerr("you need to specify source and destination args")
	}
	source := args[0]
	mut destination := args[1]
	// logica del destino
	if os.is_dir(destination){
		destination = destination + "/" + os.base(source)
	}
	mut source_fd := os.open(source) or {
		panic("Error opening ${source}")
	}
	println("Source: " + source + "\nDestination: " + destination)
	mut destination_fd := os.open_append(destination) or {
		panic("Can't open file ${destination} for writing")
	}
	//seeking
	aaa := destination_fd.tell() !
	if aaa > 0{
		source_fd.seek(aaa, os.SeekMode.start ) or {
			panic("Can't seek ${source}")
		}
	}
	source_stats := os.stat(source) !

	if source_stats.size < aaa{
		panic("Seems like you are trying to mirror not same source & destination file, if you are sure remove destination first.")
	}

	//writing
	mut total_length := aaa
	mut last := 0
	for {
		lop := source_fd.tell() !
		if last <= lop {
			last = int(lop)
		}else{
			break
		}
		nn := source_stats.size - source_fd.tell() !
		min, _ := math.minmax(nn, 3333)

		buff := source_fd.read_bytes_at(int(min), u64(total_length))
		n := buff.len
		if n > 0{
			destination_fd.write(buff) or {
				panic("Can't write to ${destination}")
			}
			total_length += n
			//source_fd.seek(total_length, os.SeekMode.start) or {
			//	panic("Can't seek source ${source}")
			//}
		}else{
			break
		}
		print("\b\b\b${total_length * 100 / source_stats.size}%")
	}
	println("Exited")
}

fn logerr(s string) {
	println(s)
	exit (1)
}

fn main2() {
}

What did you see?

you need to specify source and destination args

What did you expect to see?

this code should translate to C, it says error when used with 'v main.v -o main.o'

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Copy link

Connected to Huly®: V_0.6-21953

@venomega
Copy link
Author

forget it, prantlf is not written purely in v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant