Git Product home page Git Product logo

cx's Introduction

cx logo

CX Programming Language

Build Status Build status

CX is a general purpose, interpreted and compiled programming language, with a very strict type system and a syntax similar to Golang's. CX provides a new programming paradigm based on the concept of affordances.

Table of Contents

CX Programming Language

CX is a general purpose, interpreted and compiled programming language, with a very strict type system and a syntax similar to Golang's. CX provides a new programming paradigm based on the concept of affordances, where the user can ask the programming language at runtime what can be done with a CX object (functions, expressions, packages, etc.), and interactively or automatically choose one of the affordances to be applied. This paradigm has the main objective of providing an additional security layer for decentralized, blockchain-based applications, but can also be used for general purpose programming.

Installation

CX requires a Golang version of 1.15 or higher.

Binary Releases

You can find binary releases for most major systems on the release page.

Compiling on Linux

If you are using a apt compatible system, install the dependencies with"

sudo apt-get update

sudo apt-get install -y glade xvfb libxinerama-dev libxcursor-dev libxrandr-dev libgl1-mesa-dev libxi-dev libperl-dev libcairo2-dev libpango1.0-dev libglib2.0-dev libopenal-dev libxxf86vm-dev make

If you have not setup Golang on your machine, follow this guide to install and setup Go.

Download CX's repository using Go:

go get github.com/skycoin/cx

Get required Go dependencies with:

go get -u golang.org/x/mobile/cmd/gomobile
go get golang.org/x/mobile/gl 

Navigate to CX's repository.

Build CX's binary and install by running:

make build
make install
make test

Add the CX binary path to your operating system's $PATH. For example, in Linux:

export PATH=$PATH:$HOME/cx/bin

You should test your installation by running:

make test

Compiling on MacOS

If you have not setup Golang on your machine, follow this guide to install and setup Go.

If you do not have git installed, do so with:

brew install git

Download CX's repository using Go:

go get github.com/skycoin/cx

Navigate to CX's repository.

Build CX's binary and install by running:

make build
make install

Add the CX binary path to your operating system's $PATH. For example, in Linux:

export PATH=$PATH:$HOME/cx/bin

You should test your installation by running:

make test

Compiling on Windows

Compiling CX on Windows requires a recent version of Git to be installed.

Pacman is a utility which manages software packages.

To install pacman, download Mysys2 and run the installer.

When the installation is complete, click Run MSYS2 now.

If MSYS2 has already been installed, run it through the start menu.

You can run a full system upgrade and install required dependencies with:

pacman -Syu git mingw-w64-x86_64-openal base-devel mingw-w64-x86_64-toolchain

if [ ! -a /mingw64/lib/libOpenAL32.a ]; then ln -s /mingw64/lib/libopenal.a /mingw64/lib/libOpenAL32.a; fi

if [ ! -a /mingw64/lib/libOpenAL32.dll.a ]; then ln -s /mingw64/lib/libopenal.dll.a /mingw64/lib/libOpenAL32.dll.a; fi

You can compile CX by running:

cx-setup.bat

Test your installation by running:

cx lib/args.cx tests/main.cx ++wdir=tests ++disable-tests=issue

Updating CX

You can update your CX installation by running:

make install

Or on Windows:

cx-setup.bat

Resources and libraries

If you are interested in learning more about CX, please refer to the resources documentation.

If you want to get started with some basic example programs and tutorials check out the tutorials section.

The docs also provide a high level overview over the language.

Guide for cx compiler development

how to write cx wrapping libraty in Go Programming Language

cx's People

Contributors

amherag avatar archerixx avatar arfan499 avatar asahi3g avatar bigookie avatar brandonkoerner avatar canhdoan avatar cbrom avatar corpusc avatar diablo2050 avatar eliel00pendragon avatar eminyahyayev avatar evanlinjin avatar gz-c avatar hunzlahmalik avatar iketheadore avatar ingwal avatar ivankonevv avatar jcromerohdz avatar jdknives avatar jermy-c avatar junaidk avatar kenje4090 avatar liberxue avatar olemis avatar pratikdhanave avatar rizary avatar skycoinsynth avatar stdevyuniers avatar yuniers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cx's Issues

Can't pass array to a function with slice argument

@canhdoan commented on Jul 26

Describe the bug
An error throws when passing array to a function have a slice input.
error: function 'foo' expected input argument of type '[]i32'; '[10]i32' was provided

To Reproduce
Execute the test source below:

package main

func foo(a []i32) {
        printf("%d", len(a))
}

func main() {
        var a [10]i32
        foo(a)
}

Expected behavior
Should accept passing array to a function have slice argument

Desktop (please complete the following information):

  • OS: Kali Linux
  • CX Version 0.7.0

"continue" exits the entire current loop, AND an OUTER loop

@corpusc commented on Jul 26

Describe the bug
The "continue" keyword should just bypass the remainder of the current iteration of the current loop, and go to the next iteration of the current loop. But in CX it completely EXITs the whole loop (like "break" would do), and even exits out of an OUTER loop (but stops there, unlike the previous "break" Issue report).

To Reproduce

  1. Use this code:

package main

func main() {
for h := 0; h < 3; h++ {
printf("h: %d \n", h)

for i := 0; i < 3; i++ {
		printf("  i: %d \n", i)
		
		for j := 0; j < 3; j++ {
			if j > 0 {
				continue
			}		
					
			printf("    j: %d \n", j)
		}
		
		str.print("out of j loop")
	}
	
	str.print("out of i loop")
}

str.print("out of h loop")
}
  1. See output section below:

Expected behavior
"j: 0" is, indeed, the only feedback we should see for the j loop,
but the i loop should show values 1-3,
and all 3 of the "out of _ loop" prints should be shown.

Output
h: 0
i: 0
j: 0
h: 1
i: 0
j: 0
h: 2
i: 0
j: 0
out of h loop

Desktop:

  • OS: [Windows 10]
  • CX Version 0.7.0 full release

Increment operator only works on i32 variables

@asahi3g commented on Jul 3

To Reproduce

package main

func main()() {
	var a byte
	a++

	var b i8
	b++

	var c i16
	c++

	var d i32
	d++

	var e i64
	e++

	var f ui8
	f++

	var g ui16
	g++

	var h ui32
	h++

	var i ui64
	i++

	var j f32
	j++

	var k f64
	k++
}

Expected behavior
No compilation error.

Screenshots

error: pending_14.cx:5 function 'i32.add' expected input argument of type 'i32'; 'byte' was provided
error: pending_14.cx:5 function 'i32.add' expected receiving variable of type 'i32'; 'byte' was provided
error: pending_14.cx:8 function 'i32.add' expected input argument of type 'i32'; 'i8' was provided
error: pending_14.cx:8 function 'i32.add' expected receiving variable of type 'i32'; 'i8' was provided
error: pending_14.cx:11 function 'i32.add' expected input argument of type 'i32'; 'i16' was provided
error: pending_14.cx:11 function 'i32.add' expected receiving variable of type 'i32'; 'i16' was provided
error: pending_14.cx:18 function 'i64.add' expected input argument of type 'i64'; 'i32' was provided
error: pending_14.cx:20 function 'i32.add' expected input argument of type 'i32'; 'ui8' was provided
error: pending_14.cx:20 function 'i32.add' expected receiving variable of type 'i32'; 'ui8' was provided
error: pending_14.cx:23 function 'i32.add' expected input argument of type 'i32'; 'ui16' was provided
error: pending_14.cx:23 function 'i32.add' expected receiving variable of type 'i32'; 'ui16' was provided
error: pending_14.cx:26 function 'i32.add' expected input argument of type 'i32'; 'ui32' was provided
error: pending_14.cx:26 function 'i32.add' expected receiving variable of type 'i32'; 'ui32' was provided
error: pending_14.cx:29 function 'i32.add' expected input argument of type 'i32'; 'ui64' was provided
error: pending_14.cx:29 function 'i32.add' expected receiving variable of type 'i32'; 'ui64' was provided
error: pending_14.cx:33 function 'f32.add' expected input argument of type 'f32'; 'i32' was provided
error: pending_14.cx:36 function 'f64.add' expected input argument of type 'f64'; 'i32' was provided

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

No compilation error when appending a value of type B in a slice of type []A

@asahi3g commented on Jul 3

To Reproduce

package main

type fooA struct {
	f f32
}

type fooB struct {
	d f64
	i i32
}

func main()() {
	var sa []fooA
	var b fooB
	sa = append(sa, b)
	panic(true, false, "must not compile")
}

Expected behavior
Compilation error.

Screenshots

byts1 [1]
byts2 [0]
pending_16.cx: 16: result was not equal to the expected value; must not compile

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

len() of struct slices can be hugely wrong

@corpusc commented on Jul 28

Describe
...and it will give different numbers, affected by the values of a struct field.

To Reproduce

  1. use this code:

package main

type TextInfo struct {
Text str
Font str
Size f32
Wid f32 // caches string measure queries
Hei f32
}

func main() {
var texts []TextInfo
texts = []TextInfo{TextInfo{Text:"hmm"}}
printf("len %d \n", len(texts))
}

  1. Now add an extra 'm' character to the "Text" field, and watch CX report a different size

Desktop:

  • OS: Windows 10
  • CX Version 0.7.0 full release

defining & initializing slices/arrays on 1 line doesn't work with struct, PANICS

@corpusc commented on Jul 3

...and gives no file/line info.
This is with a single field, my next Issue report shows a different kind of error when you have 3 fields. At least you get some file/line info in THAT case (but not THIS Issue's case).

To Reproduce
Steps to reproduce the behavior:

  1. Use code:

package main

type Color3 struct {
R f32
}

func main() {
var nums [3]i32 = [3]i32{ 1, 2, 3 }
var colors [1]Color3 = [1]Color3{Color3{R: 1.0}}
}

If you comment out the "var colors" line, you see it works fine with i32s
Screenshots
panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cxgo/actions.CheckTypes(0xc000059b80)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:620 +0x10b6
github.com/skycoin/cx/cxgo/actions.FunctionDeclaration(0xc00005c680, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0000542a0, 0x8, 0xc)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:166 +0x48f
github.com/skycoin/cx/cxgo/parser.yyParse(0x100cd60, 0xc000092000, 0xc000092000)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:1744 +0x1d40
github.com/skycoin/cx/cxgo/parser.Parse(0xc000092000, 0xc00018c000)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:18 +0x3e
main.main()
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/main.go:826 +0xf52

Desktop:

  • OS: Windows 10
  • CX Version 0.7.0 full release

Compilation error when using inline initalization of a slice var as function argument.

@asahi3g commented on Jul 3

To Reproduce

package main

func fooi(slice []i32) {
	test(len(slice), 3, "")
	test(slice[0], 1, "")
	test(slice[1], 2, "")
	test(slice[2], 3, "")
}

func foos(slice []str) {
	test(len(slice), 3, "")
	test(slice[0], "foo", "")
	test(slice[1], "slice", "")
	test(slice[2], "str", "")
}

func main()() {
	fooi([]i32{1, 2, 3})
	foos([]str {"foo", "slice", "str"})
}

Expected behavior
No compilation error.

Screenshots

error: pending_0.cx:18 identifier '*lcl_2' does not exist
error: pending_0.cx:18 identifier '*lcl_2' does not exist
error: pending_0.cx:18 identifier '*lcl_2' does not exist
error: pending_0.cx:18 identifier '*lcl_2' does not exist
error: pending_0.cx:18 identifier '*lcl_2' does not exist
error: pending_0.cx:18 identifier '*lcl_2' does not exist
error: pending_0.cx:18 identifier '*lcl_2' does not exist
error: pending_0.cx:19 identifier '*lcl_4' does not exist
error: pending_0.cx:19 identifier '*lcl_4' does not exist
error: pending_0.cx:19 identifier '*lcl_4' does not exist
error: pending_0.cx:19 identifier '*lcl_4' does not exist
error: pending_0.cx:19 identifier '*lcl_4' does not exist
error: pending_0.cx:19 identifier '*lcl_4' does not exist
error: pending_0.cx:19 identifier '*lcl_4' does not exist

Desktop:

  • OS: Linux
  • CX Version 0.7.0, commit : f999780

Add Unicode/ASCII encoding and decoding functios for strings/byte slices

@ReewassSquared commented on Aug 11

I think a function such as str.to_scii : str -> []byte and str.to_unicode : str -> []byte, as well as str.from_ascii : []byte -> str and str.from_unicode : []byte -> str would be very useful.

As far as I know the only way to convert ASCII strings into ASCII codes is using a lookup table, and isn't possible for Unicode strings as far as I know.

Array of Structure2(package2) in Structure1(package1) fails

@4rchim3d3s commented on May 27

package package1

type Button struct {
name str
x f32
y f32
width i32
height i32
active bool
active_texture i32
inactive_texture i32
}

type Screen struct {
name str
width i32
height i32
has_background bool
background i32
image_count i32
button_count i32
buttons [20]Button // <-- this works and with this i can access all functions on
buttonpackage where the same struct is declared
}


package buttonpackage

type Button struct {
name str
x f32
y f32
width i32
height i32
active bool
active_texture i32
inactive_texture i32
}

package package1

type Screen struct {
name str
width i32
height i32
has_background bool
background i32
image_count i32
button_count i32
buttons [20]buttonpackage.Button // <-- this doesn't work
}
Desktop (please complete the following information):

  • OS: WIN10
  • CX Version [0.7beta] and didn't work on 0.6.2

Windows CX-Chains newcoin.go vs. cxcoin.go

@4rchim3d3s commented on Jul 31

Describe the bug
Try to use cx chains tutorial with Windows10
path error

To Reproduce
0. Compile CX on Windows10 with cx-setup.bat

  1. cli addressGen works in tutorial described as skycoin-cli addressGen
  2. unclear if i have to change the fiber.toml in cx folder or in skycoin folder (changed both)
  3. cx --blockchain --heap-initial 100 --stack-size 100 --secret-key 56a4130ca867c3ead4b9a792173492727f494a8229f30fd7be04ee20395cf621 --public-key 024b176b72cdf145b1c2aa26c1ae5271d3ab4f998bddab9313390a46c245e52170 D:\Programs\GO_CX\src\github.com\skycoin\CX/examples/blockchain/counter-bc.cx
    panic: CreateFile D:\Programs\GO_CX\src\github.com\skycoin\cx\cmd\cxcoin\cxcoin.go: The system cannot find the path specified.
  4. (changed ./examples.. to the direct folder, didn`t work like described in Tutorial)
  5. changed name of newcoin folder and newcoin.go to cxcoin folder and cxcoin.go ( because of panic described in 3.)
  6. C:\Users\Userz>cx --blockchain --heap-initial 100 --stack-size 100 --secret-key 56a4130ca867c3ead4b9a792173492727f494a8229f30fd7be04ee20395cf621 --public-key 024b176b72cdf145b1c2aa26c1ae5271d3ab4f998bddab9313390a46c245e52170 D:\Programs\GO_CX\src\github.com\skycoin\CX/examples/blockchain/counter-bc.cx
    ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: error: flag provided but not defined: -block-publisher
  7. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner:
  8. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: NAME:
  9. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: newcoin - newcoin is a helper tool for creating new fiber coins
  10. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner:
  11. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: USAGE:
  12. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: cxcoin.exe [global options] command [command options] [arguments...]
  13. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner:
  14. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: VERSION:
  15. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: 0.1
  16. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner:
  17. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: COMMANDS:
  18. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: createcoin Create a new coin from a template file
  19. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: help, h Shows a list of commands or help for one command
  20. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner:
  21. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: GLOBAL OPTIONS:
  22. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: --help, -h show help
  23. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[32mINFO๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m Scanner: --version, -v print the version
  24. ๏ฟฝ[90m[2019-07-31T17:48:58+02:00]๏ฟฝ[0m ๏ฟฝ[31mERROR๏ฟฝ[0m๏ฟฝ[36m [newcoin]:๏ฟฝ[0m error getting genesis block

genesis signature:
panic: Config File "fiber" Not Found in "[C:\Users\Userz]"

goroutine 1 [running, locked to thread]:
main.main()
D:/Programs/GO_CX/src/github.com/skycoin/cx/cxgo/main.go:950 +0x6113

Screenshots
image

Desktop (please complete the following information):

  • OS: Win10
  • CX Version [0.7.1]
  • Environment Variables (don`t know if necessary):
    • CXPATH: "D:\Programs\CX"
    • GOPATH: "D:\Programs\GO_CX"
    • PATH: - "%GOPATH%\bin" - "%CXPATH%"

No compilation error when appending to a pointer to a slice

@asahi3g commented on Jul 3

To Reproduce

package main

func main()() {
	var si []i32
	var psi *[]i32 = &si
	psi = append(psi, 4)
	panic(true, false, "must not compile")
}

Expected behavior
Compilation error eg golang :
first argument to append must be slice; have *[]int32
Screenshots

byts1 [1]
byts2 [0]
pending_9.cx: 6: result was not equal to the expected value; must not compile

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

when initializing slices/arrays (with values), can't have final closed brace on it's own line

@corpusc commented on Jun 27

Describe

i find the neatest way to do this is like:

package main

func main() {
var s [3]str = [3]str{
"a",
"b",
"c"
}
}

To Reproduce

  1. Enter code above

Expected behavior
I'd like to format my code like this for neatness, and have it work with no error.

ERROR REPORT
c.cx:7: syntax error: unexpected SEMICOLON
(points to the last data element "c")

Desktop (please complete the following information):

  • OS: Windows 10
  • CX Version 0.7.0. full release

func defined with no arguments, called WITH arguments causes PANIC

@corpusc commented on Jun 22

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

  1. Try this code:
    package main

func main() {
cat(1)
}

func cat() {
}

  1. just removing the 1 FIXES it
  2. using i32 vars, and both vars & literals of type f32 will also cause the panic (i stopped trying various types at that point)

Expected behavior
Reporting the file & line number of the erroneous func call, and telling me it is defined with no arguments.

ERROR text
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cx.runtimeErrorInfo(0xe12b40, 0xcda3a0, 0xcda301, 0x5)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cx/utilities.go:822 +0x298
github.com/skycoin/cx/cx.RuntimeError()
C:/Users/Amaury/go/src/github.com/skycoin/cx/cx/utilities.go:858 +0x178
panic(0xe12b40, 0xcda3a0)
C:/Go/src/runtime/panic.go:513 +0x1c7
github.com/skycoin/cx/cx.(*CXCall).ccall(0xc0003a4000, 0xc0006be000, 0x0, 0x0)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cx/execute.go:335 +0x5ec
github.com/skycoin/cx/cx.(*CXProgram).Run(0xc0006be000, 0xed5301, 0xc00008f418, 0xffffffffffffffff, 0x0, 0x0)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cx/execute.go:118 +0x127
github.com/skycoin/cx/cx.(*CXProgram).RunCompiled(0xc0006be000, 0x0, 0x0, 0x0, 0x0, 0xc00006e5b0, 0x0)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cx/execute.go:200 +0x224
main.main()
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/main.go:1003 +0x21d1

Desktop

  • OS: Windows 10
  • CX Version 0.7.0 full release

Cx is not supporting short-circuit evaluation

@asahi3g commented on May 10

Describe the bug
Cx is not supporting short-circuit evaluation

To Reproduce

package main

var count i32
func True(i i32) (out bool) {
	out = true
	count = i
}

func False(i i32) (out bool) {
	out = false
	count = i
}

func foo(b0 bool, b1 bool, b2 bool) {
}

func main()() {
	var b bool

	b = True(4) || True(5)
	test(count, 4, "a")

	if True(6) == true || True(7) == true {
	}
	test(count, 6, "b")

	b = False(8) && True(9)
	test(count, 8, "c")

	if False(10) == true && True(11) == true {
	}
	test(count, 10, "d")

	foo(True(12), True(13), True(14))
	test(count, 14, "e")
}

Expected behavior
Cx must support short-circuit an test must pass.

Screenshots

byts1 [5 0 0 0]
byts2 [4 0 0 0]
pending_1.cx: 21: result was not equal to the expected value; a
byts1 [7 0 0 0]
byts2 [6 0 0 0]
pending_1.cx: 25: result was not equal to the expected value; b
byts1 [9 0 0 0]
byts2 [8 0 0 0]
pending_1.cx: 28: result was not equal to the expected value; c
byts1 [11 0 0 0]
byts2 [10 0 0 0]
pending_1.cx: 32: result was not equal to the expected value; d

Desktop (please complete the following information):

  • OS: linux
  • CX Version 0.6.2 commit 4ba0d2d

Compilation error when using neg operator on struct fields

@asahi3g commented on Jul 3

To Reproduce

package main

type too struct {
	x i32
	y i32
}

func main()() {
	var t too
	t.x = 12
	t.y = -15

	t.x = -t.x
	t.y = -t.y
	test(t.x, -12, "must equals -12")
	test(t.y, 15, "must equals 15")
}

Expected behavior
No compilation error and test pass

Screenshots

error: pending_17.cx:14 identifier 'x' does not exist
error: pending_17.cx:15 identifier 'y' does not exist

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

len(str) vs. len(struct.struct.str)

@4rchim3d3s commented on Aug 16

Describe the bug

struct.struct.str =""

len("") returns 0
len(struct.struct.str) returns 1065353216

str.print(struct.struct.str) prints out ""

To Reproduce
make structure that has got a structure that has an strinng value
set value to ""

call len like described above.

Expected behavior
returns 1065353216 instead of 0

Desktop (please complete the following information):

  • OS: win10
  • CX Version 0.7.1

putting commas inside slice indexers (square brackets) gives no error

@corpusc commented on Jul 3

Describe:
It apparently ignores everything after the comma, and works as if you just typed the 1st (leftmost) number.

To Reproduce
Steps to reproduce the behavior:

  1. Try this:

package main

type Shape struct {
Cells [][][][]bool
}

var Curr Shape

func main() {
Curr.Cells[0] = append(Curr.Cells[0], true)
Curr.Cells[0,0] = append(Curr.Cells[0,0], true)
Curr.Cells[0,0] = append(Curr.Cells[0,0], true)
Curr.Cells[0,0,0] = append(Curr.Cells[0,0,0], true)
Curr.Cells[0,0,0] = append(Curr.Cells[0,0,0], true)
Curr.Cells[0,0,0] = append(Curr.Cells[0,0,0], true)
i32.print(len(Curr.Cells[0]))
i32.print(len(Curr.Cells[0,0]))
i32.print(len(Curr.Cells[0,0,0]))
}

Expected behavior
An error message to let you know indexing doesn't work this way in CX (I believe it DOES in some other languages)

Desktop:

  • OS: Windows 10
  • CX Version 0.7.0 full release

Slice literals: Problem with temporary variables in multi-dimensional slices.

@amherag commented on Sept 14

Describe the bug

Trying to create multi-dimensional slice literals is buggy.

To Reproduce

Steps to reproduce the behavior:

  1. Type in the following code in a test.cx file:
    package main

func main() {

	var i [][][]i32
	i = [][][]i32{
		[][]i32{[]i32{1, 2, 3}, []i32{10, 20, 30, 40}},
		[][]i32{[]i32{4, 5, 6}}}

	i32.print(i[0][0][0])
	i32.print(i[0][0][1])
	i32.print(i[0][0][2])
}
  1. Run the source file with cx -r test.cx
  2. Run the CX meta-command :dp to display the AST.
  3. Notice that the types associated to the temporary variables created by the CX parser are not correct.

Expected behavior
The parser should create the temporary variables involved in the creation of an slice literal with the correct types (which include the dimensions declared for i).

Desktop (please complete the following information):

OS: Linux, Debian.
CX from branch in PR #479 .

No compilation error when assigning an literal which overflow the receiving type

@asahi3g commented on May 10

Describe the bug
No compilation error when assigning an literal which overflow the receiving type

To Reproduce

package main
func main ()() {
	var b0 byte = 256B
	var b1 byte = -1B
	test(false, true, "must not compile")
}

Expected behavior
Compilation error like golang.
eg : "constant -1 overflows byte"

Screenshots

byts1 [0]
byts2 [1]
pending_0.cx: 6: result was not equal to the expected value; must not compile

Desktop (please complete the following information):

  • OS: linux
  • CX Version 0.6.2 commit 4ba0d2d

can't initialize multidimensional arrays/slices with values

@corpusc commented on Jun 27

To Reproduce

  1. Enter this code:
    package main

func main() {
var i [][]i32 = [][]i32{ {1, 2}, {3, 4} }
}

  1. See error:
    c.cx:4: syntax error: unexpected LBRACE

Expected behavior
No error

Desktop (please complete the following information):

  • OS: Windows 10
  • CX Version 0.7.0 full release

Panic when indexing a non indexable variable.

@asahi3g commented on Jul 3

To Reproduce

package main

func main()() {
	var b bool = true
	var bb bool = b[0]
	panic(true, false, "must not compile")
}

Expected behavior
No panic.

Screenshots

error: pending_13.cx:5 invalid indexing
panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cxgo/actions.PreFinalSize(0xc000198740, 0xc0001fcb40, 0xc0001fc6c0)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:1161 +0x1ea
github.com/skycoin/cx/cxgo/actions.SetFinalSize(0xc0001988d8, 0xc0001fcb40)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:1131 +0xa6
github.com/skycoin/cx/cxgo/actions.ProcessExpressionArguments(0xc0001988d8, 0xc0001988b0, 0xc000198898, 0xc000082680, 0xc000266068, 0x1, 0x1, 0xc0000930e0, 0x1)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:397 +0x1de
github.com/skycoin/cx/cxgo/actions.FunctionDeclaration(0xc000082680, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000064040, 0x5, 0x8)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:142 +0x377
github.com/skycoin/cx/cxgo/parser.yyParse(0xfd3fe0, 0xc000094000, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:1743 +0x1b31
github.com/skycoin/cx/cxgo/parser.Parse(...)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:18
main.main()
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/main.go:826 +0xf33

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

pointer to structure array indexed object

@4rchim3d3s commented on Aug 13

Describe the bug

Trying to pass a pointer to an address of a structure within an array

error: cx-template\inputs\inputHandler.cx:222 invalid indexing
error: cx-template\inputs\inputHandler.cx:222 function 'updateSliderPosition' expected input argument of type '*Slider'; '*[20]Slider' was provided

To Reproduce
Steps to reproduce the behavior:

  1. git clone https://github.com/4rchim3d3s/cx-template
  2. change screenHandler.cx line 422-425 into
func updateSliderPosition(slider *sliderHandler.Slider, mouse_x f64)(){
	*slider.slider_x = absolute2relativeX(f64.i32(mouse_x), current_screen.width)
	*slider = sliderHandler.limitPosition(slider)
	*slider = sliderHandler.setValueByPosition(slider)
}
  1. change inputHandler.cx line 222 to

screenHandler.updateSliderPosition(&screen.sliders[i], mouse_x)

Desktop (please complete the following information):

  • OS: WIN10
  • CX Version 0.7.1

String conversion in method doesn't work

@ingwal commented on Jun 18

The following program does not work. If you uncomment the line marked "This gives a compilation error", you will get a compilation error. :)

package main

type Foo struct {
x i32
}

func (f *Foo) Print() {
// This gives a compilation error:
//str.print("X: " + i32.str((*f).x))

// This works
str.print("X: ")
str.print(i32.str((*f).x))

}

func main() {
var foo Foo
foo.x = 3

foo.Print()

}
Expected behavior
The marked line should work too

Desktop (please complete the following information):

  • OS: Linux
  • CX Version 0.7.0

can't use multidimensional arrays/slices inside a struct

@corpusc commented on Jul 2

To Reproduce
Steps to reproduce the behavior:

  1. Use this code:
    package main

type Shape struct {
Cells [5][5]bool
}

var Curr Shape

func main() {
Curr.Cells[0][0] = true
}

  1. Remove a "[5]" and a "[0]", and the single dimension works
    ERROR MSG

error: c.cx:10 invalid indexing
error: c.cx:10 invalid indexing
error: c.cx:11 cannot assign value of type 'bool' to identifier 'Cells' of type '[5][5]bool'

Desktop

  • OS: Windows 10
  • CX Version 0.7.0 full release

"." as 1st arg to CX gives false runtime error (but WORKS as 2nd arg)

@corpusc commented on Sep 3

when using a common dir with a relative path, you have to move the "." argument out of the 1st argument slot (i did not try "." in the 3rd or higher numbered slots).
making an argument for every file in the CWDir instead of using "." will also work, FWIW.

To Reproduce

  1. Go into a working project dir
  2. (one that works properly, when run with "cx .")
  3. Make a "..\2DFWork" dir
  4. Move 1 of your files there
  5. Run it with "cx . ..\2DFWork\app.cx" <--- ERROR
  6. Run it with "cx ..\2DFWork\app.cx ." <--- IT WORKS

ERROR
"error: draw.cx:57, CX_RUNTIME_ERROR, runtime error: integer divide by zero"

and there was no cases of "/" or "div" in draw.cx.
i believe in my experiments it also reported some OTHER erroneous message.
but the same source code works fine if "." isn't the 1st argument
(however i did not try it in 3rd or higher slot).

Desktop:

  • OS: Windows 10
  • CX Version 0.7.0 full release

Compiler Error: Can't use infinite loop

@canhdoan commented on Jul 26

Describe the bug
Can't execute an infinite loop with true value as the link

To Reproduce
See the test source

package main

func main() {
        for true {
                printf("looping!!!")
        }
}

Desktop (please complete the following information):

  • OS: Kali Linux
  • CX Version 0.7.0

Compilation error and panic when using += operator

@asahi3g commented on Jul 3

To Reproduce

package main

func main()() {
	var i i32 = 2
	var j i32 = 3
	j += i
	test(j, 5, "")
}

Expected behavior
No compilation error and test pass.

Screenshots

error: pending_15.cx:7 'i' redeclared
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x8bb8f6]

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cxgo/actions.ProcessLocalDeclaration(...)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:436
github.com/skycoin/cx/cxgo/actions.ProcessExpressionArguments(0xc0001988d8, 0xc0001988b0, 0xc000198898, 0xc000082680, 0xc0001a4250, 0x2, 0x2, 0xc000093220, 0x1)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:361 +0x256
github.com/skycoin/cx/cxgo/actions.FunctionDeclaration(0xc000082680, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000064040, 0x7, 0x8)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:142 +0x377
github.com/skycoin/cx/cxgo/parser.yyParse(0xfd3fe0, 0xc000094000, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:1743 +0x1b31
github.com/skycoin/cx/cxgo/parser.Parse(...)
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:18
main.main()
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/main.go:826 +0xf33

Desktop:

OS: Linux
CX Version 0.0.7, commit: f999780

gl.Enable() & gl.Disable() missing some parameters

@0pcom commented on Jul 19

CX version 0.7.0
This version of cx includes (I think) OpenGL version 2.1

A reference of the parameters for gl.Begin() & gl.End() can be found here

Here is the OpenGL Programming Guide for version 2.1 from which I am attempting to run some examples.

For additional reference; the following functions as desired:

gl.Init()
gl.Enable(gl.BLEND)
gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

Other parameters from the list which at least appear to exist:

gl.Enable(gl.COLOR_SUM)

gl.Enable(gl.CULL_FACE)

gl.Enable(gl.DEPTH_TEST)

gl.Enable(gl.DITHER)

gl.Enable(gl.LIGHTING)

gl.Enable(gl.LINE_SMOOTH)

gl.Enable(gl.POINT_SMOOTH)

gl.Enable(gl.POLYGON_SMOOTH)

gl.Enable(gl.SCISSOR_TEST)

gl.Enable(gl.STENCIL_TEST)

gl.Enable(gl.TEXTURE_2D)

However some other parameters give panic: struct not found in package 'gl'
I can't say for certain that the absence of these parameters is a bug, incompleteness, or if it's the documentation for this which is missing.

The following is a list of parameters which appear to be missing from CX but which are described in the OpenGL reference pages:

gl.Enable(gl.ALPHA_TEST)
gl.AlphaTest()

gl.Enable(gl.AUTO_NORMAL)
gl.AutoNormal()

gl.Enable(gl.CLIP_PLANEi)
gl.ClipPlanei()

gl.Enable(gl.COLOR_LOGIC_OP)
gl.ColorLogicOp()

gl.Enable(gl.COLOR_MATERIAL)
gl.ColorMaterial()

gl.Enable(gl.COLOR_TABLE)
gl.ColorTable()

gl.Enable(gl.CONVOLUTION_1D)
gl.Convolution1D()

gl.Enable(gl.CONVOLUTION_2D)
gl.Convolution2D()

gl.Enable(gl.FOG)
gl.Fog()

gl.Enable(gl.HISTOGRAM)
gl.Histogram()

gl.Enable(gl.INDEX_LOGIC_OP)
gl.IndexLogicOp()

gl.Enable(gl.LIGHTi)
gl.Lighti()

gl.Enable(gl.LINE_STIPPLE)
gl.LineStipple(1, 0xF0F0)

gl.Enable(gl.MAP1_COLOR_4)
gl.Map1Color4()

gl.Enable(gl.MAP1_INDEX)
gl.Map1Index()

gl.Enable(gl.MAP1_NORMAL)
gl.Map1Normal()

gl.Enable(gl.MAP1_TEXTURE_COORD_1)
gl.Map1TextureCoord1

gl.Enable(gl.MAP1_TEXTURE_COORD_2)
gl.Map1TextureCoord2()

gl.Enable(gl.MAP1_TEXTURE_COORD_3)
gl.Map1TextureCoord3()

gl.Enable(gl.MAP1_TEXTURE_COORD_4)
gl.Map1TextureCoord4()

gl.Enable(gl.MAP1_VERTEX_3)
gl.Map1Vertex3()

gl.Enable(gl.MAP2_COLOR_4)
gl.Map2Color4()

gl.Enable(gl.MAP2_INDEX)
gl.Map2Index()

gl.Enable(gl.MAP2_NORMAL)
gl.Map2Normal()

gl.Enable(gl.MAP2_TEXTURE_COORD_1)
gl.Map2TextureCoord1()

gl.Enable(gl.MAP2_TEXTURE_COORD_2)
gl.Map2TextureCoord2()

gl.Enable(gl.MAP2_TEXTURE_COORD_3)
gl.Map2TextureCoord3()

gl.Enable(gl.MAP2_TEXTURE_COORD_4)
gl.Map2TextureCoord4()

gl.Enable(gl.MAP2_VERTEX_3)
gl.Map2Vertex3()

gl.Enable(gl.MINMAX)
gl.Minimax()

gl.Enable(gl.MULTISAMPLE)
gl.Multisample()

gl.Enable(gl.NORMALIZE)
gl.Normalize()

gl.Enable(gl.POINT_SPRITE)
gl.PointSprite()

gl.Enable(gl.POLYGON_OFFSET_FILL)
gl.PolygonOffsetFill()

gl.Enable(gl.POLYGON_OFFSET_LINE)
gl.PolygonOffsetLine()

gl.Enable(gl.POLYGON_OFFSET_POINT)
gl.PolygonOffsetPoint()

gl.Enable(gl.POLYGON_STIPPLE)
gl.PolygonStipple()

gl.Enable(gl.POST_COLOR_MATRIX_COLOR_TABLE)
gl.PostColorMatrixTable()

gl.Enable(gl.POST_CONVOLUTION_COLOR_TABLE)
gl.PostConvolutionColorTable()

gl.Enable(gl.RESCALE_NORMAL)
gl.RescaleNormal()

gl.Enable(gl.SAMPLE_ALPHA_TO_COVERAGE)
gl.SampleAlphaToCoverage()

gl.Enable(gl.SAMPLE_ALPHA_TO_ONE)
gl.SampleAlphaToOne()

gl.Enable(gl.SAMPLE_COVERAGE)
gl.SampleCoverage()

gl.Enable(gl.SEPARABLE_2D)
gl.Separable2d()

gl.Enable(gl.TEXTURE_1D)
gl.Texture1d()

gl.Enable(gl.TEXTURE_3D)
gl.Texture3d()

gl.Enable(gl.TEXTURE_CUBE_MAP)
gl.TextureCubeMap()

gl.Enable(gl.TEXTURE_GEN_Q)
gl.TextureGenQ()

gl.Enable(gl.TEXTURE_GEN_R)
gl.TextureGenR()

gl.Enable(gl.TEXTURE_GEN_S)
gl.TextureGenS()

gl.Enable(gl.TEXTURE_GEN_T)
gl.TextureGenT()

gl.Enable(gl.VERTEX_PROGRAM_POINT_SIZE)
gl.VertexProgramPointSize()

gl.Enable(gl.VERTEX_PROGRAM_TWO_SIDE)
gl.VertexProgramTwoSide()

Escape code errors

@ReewassSquared commented on Jun 9

This is expanding on issue #306.

escape codes for single and double quotes do not function as intended. Single quotes throws an error "unexpected single quote".

Not sure why the error would be happening for single quotes as well.

Compilation error when using multiple return values in short hand expression.

@asahi3g commented on Jul 3

Describe the bug
Can't declare and inline initialize multiple variable from return values of a function call.

To Reproduce

package main

func foo()(i i32, f f32) {
	i = 5
	f = 1.0
}

func main()(){
	i, f := foo()

	test(i, 5, "")
	test(f, 1.0, "")
}

Expected behavior
No compilation error and test pass.

Screenshots

error: pending_7.cx:9 identifier 'i' does not exist
error: pending_7.cx:9 function 'foo' expected receiving variable of type 'i32'; 'ident' was provided
error: pending_7.cx:9 function 'foo' expected receiving variable of type 'f32'; 'i32' was provided
error: pending_7.cx:11 identifier 'i' does not exist
error: pending_7.cx:15 first and second input arguments' types are not equal in 'test' call ('ident' != 'i32')
error: pending_7.cx:15 first and second input arguments' types are not equal in 'test' call ('i32' != 'f32')

Desktop:

  • OS: Linux
  • CX Version 0.7.0 commit: f999780

def'ing & init'ing slices/arrays on 1 line CLAIMS STRUCT DOESN'T EXIST (with MULTIFIELD structs)

@corpusc commented on Jul 3

Describe the bug
It still panics like Issue 437, but gives some file/line info before panicking.

To Reproduce
1.

package main

type Color3 struct {
R f32
G f32
B f32
}

func main() {
var nums []i32 = []i32{ 1, 2, 3 }
var colors []Color3 = []Color3{ Color3{ R: 1.0, G: 1.0, B: 1.0 } }
}

Expected behavior
For it to not lie about struct, and for it to work.

Screenshots

error: c.cx:11 identifier 'Color3' does not exist
error: c.cx:11 field 'R' in struct literal of type 'Color3' expected argument of type 'Color3'; 'f32' was provided
error: c.cx:11 cannot assign value of type 'f32' to identifier 'R' of type ''
error: c.cx:11 identifier 'Color3' does not exist
error: c.cx:11 field 'G' in struct literal of type 'Color3' expected argument of type 'Color3'; 'f32' was provided
error: c.cx:11 cannot assign value of type 'f32' to identifier 'G' of type ''
panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cxgo/actions.CheckTypes(0xc000063cc0)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:620 +0x10b6
github.com/skycoin/cx/cxgo/actions.FunctionDeclaration(0xc00006e5b0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00009c240, 0xa, 0xc)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:166 +0x48f
github.com/skycoin/cx/cxgo/parser.yyParse(0x100cd60, 0xc0000aa000, 0xc0000aa000)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:1744 +0x1d40
github.com/skycoin/cx/cxgo/parser.Parse(0xc0000aa000, 0xc0001a8000)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:18 +0x3e
main.main()
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/main.go:826 +0xf52

Desktop (please complete the following information):

  • OS: Windows 10
  • CX Version 0.7.0 full release

List of non-working CX examples

@0pcom commented on May 22

Describe the bug

Nonworking CX examples

To Reproduce
Steps to reproduce the behavior:

  1. Go to cx examples dir
  2. run each example with cx <example_name>.cx

Expected behavior

Example should complete without errors

Desktop (please complete the following information):

  • OS: Arch Linux x86_64
  • CX Version: 0.7beta

Additional context

Non-working CX examples:

examples/

$cx bubble-sort.cx
error: bubble-sort.cx:38 function 'i32.add' expected receiving variable of type 'i32'; 'ident' was provided
error: bubble-sort.cx:38 wrong index type; expected either 'i32' or 'i64', got 'ident'


$ cx digital-root.cx
        Digital Root Example
I will set the value for you :)
The value is 30
And I will call digiatlRoot() with base 10
error: digital-root.cx:14, CX_RUNTIME_SLICE_INDEX_OUT_OF_RANGE, 9
===Callstack===
>>> digiatlRoot()
Inputs
	digital-root.cx:12 : digiatlRoot() : 30
Inputs
	digital-root.cx:12 : digiatlRoot() : 10
Outputs
	digital-root.cx:12 : digiatlRoot() : []
Expressions
 	digital-root.cx:16 : i32.add() : 0
	digital-root.cx:20 : i32.gteq() : false

>>> main()
Expressions
 	digital-root.cx:38 : i32.gt() : true
	digital-root.cx:30 : digiatlRoot() : []

goroutine 1 [running, locked to thread]:
runtime/debug.Stack(0xc000069740, 0xc35400, 0xc000069690)
	/usr/local/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/skycoin/cx/cx.runtimeErrorInfo(0xc346c0, 0xe7e078, 0xe7e001, 0x5)
	/home/amherag/go/src/github.com/skycoin/cx/cx/utilities.go:835 +0x21d
github.com/skycoin/cx/cx.RuntimeError()
	/home/amherag/go/src/github.com/skycoin/cx/cx/utilities.go:858 +0x171
panic(0xc346c0, 0xe7e078)
	/usr/local/go/src/runtime/panic.go:513 +0x1b9
github.com/skycoin/cx/cx.CalculateDereferences(0xc00024e900, 0xc0000e11e0, 0x5, 0x0)
	/home/amherag/go/src/github.com/skycoin/cx/cx/op.go:52 +0x94d
github.com/skycoin/cx/cx.GetFinalOffset(0x5, 0xc00024e900, 0x5)
	/home/amherag/go/src/github.com/skycoin/cx/cx/op.go:151 +0x6c
github.com/skycoin/cx/cx.opIdentity(0xc0002543c0, 0x5)
	/home/amherag/go/src/github.com/skycoin/cx/cx/op_misc.go:34 +0x89
github.com/skycoin/cx/cx.init.2.func1(0xc0001c01c0)
	/home/amherag/go/src/github.com/skycoin/cx/cx/opcodes_core.go:937 +0x121
github.com/skycoin/cx/cx.init.3.func1(0xc0001c01c0)
	/home/amherag/go/src/github.com/skycoin/cx/cx/opcodes_extra.go:594 +0xf33
github.com/skycoin/cx/cx.(*CXCall).ccall(0xc00030e018, 0xc0001c01c0, 0x0, 0x0)
	/home/amherag/go/src/github.com/skycoin/cx/cx/execute.go:278 +0x35d
github.com/skycoin/cx/cx.(*CXProgram).Run(0xc0001c01c0, 0xd7f101, 0xc0000e1550, 0xffffffffffffffff, 0x0, 0x0)
	/home/amherag/go/src/github.com/skycoin/cx/cx/execute.go:118 +0x120
github.com/skycoin/cx/cx.(*CXProgram).RunCompiled(0xc0001c01c0, 0x0, 0x0, 0x0, 0x0, 0xc00009c820, 0x0)
	/home/amherag/go/src/github.com/skycoin/cx/cx/execute.go:200 +0x21d
main.main()
	/home/amherag/go/src/github.com/skycoin/cx/cxgo/main.go:813 +0x10cf


$ cx errors.cx
error: errors.cx:7, CX_RUNTIME_ERROR, runtime error: integer divide by zero
===Callstack===
>>> main()
Expressions
 	errors.cx:4 : identity() : 10
	errors.cx:5 : identity() : 5.5
	errors.cx:7 : i32.div() : 0

goroutine 1 [running, locked to thread]:
runtime/debug.Stack(0xa, 0xc0000e50c0, 0x3)
	/usr/local/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/skycoin/cx/cx.runtimeErrorInfo(0xcbf2c0, 0x15e1c80, 0x15e1c01, 0x5)
	/home/amherag/go/src/github.com/skycoin/cx/cx/utilities.go:835 +0x21d
github.com/skycoin/cx/cx.RuntimeError()
	/home/amherag/go/src/github.com/skycoin/cx/cx/utilities.go:858 +0x171
panic(0xcbf2c0, 0x15e1c80)
	/usr/local/go/src/runtime/panic.go:513 +0x1b9
github.com/skycoin/cx/cx.opI32Div(0xc0000b32c0, 0x0)
	/home/amherag/go/src/github.com/skycoin/cx/cx/op_i32.go:67 +0x124
github.com/skycoin/cx/cx.init.2.func1(0xc000624000)
	/home/amherag/go/src/github.com/skycoin/cx/cx/opcodes_core.go:1042 +0x836



$ cx temp-converter.cx
error: temp-converter.cx:15 operands are not of the same type

examples/book/

$ cx affordances-expression.cx
error: affordances-expression.cx:16 cannot assign value of type '[]aff' to identifier 'tgt' of type 'aff'
error: affordances-expression.cx:20 cannot assign value of type '[]aff' to identifier 'fltrs' of type 'aff'

$ cx affordances-filter.cx
error: affordances-filter.cx:13 cannot assign value of type '[]aff' to identifier 'fltrs' of type 'aff'

$ cx cxbase-program.cx
cxbase-program.cx:25: syntax error: unexpected IDENTIFIER

$ cx cxbase-sum.cx
cxbase-sum.cx:3: syntax error: unexpected LPAREN

$ cx datatypes-slices-native.cx
error: datatypes-slices-native.cx:8 function 'make' not found in package 'main'
error: datatypes-slices-native.cx:11 function 'make' not found in package 'main'

$ cx datatypes-slices-native.cx
error: datatypes-slices-native.cx:8 function 'make' not found in package 'main'
error: datatypes-slices-native.cx:11 function 'make' not found in package 'main'

$ cx deserialization-program.cx
error: deserialization-program.cx:8 function 'serialize' expected input argument of type 'aff'; '[]aff' was provided
error: deserialization-program.cx:8 function 'serialize' expected receiving variable of type 'byte'; '[]byte' was provided
error: deserialization-program.cx:9 function 'deserialize' expected input argument of type 'byte'; '[]byte' was provided

$ cx functions-lexical-scoping.cx
error: functions-lexical-scoping.cx:4 identifier 'x' does not exist
error: functions-lexical-scoping.cx:4 function 'i32.print' expected input argument of type 'i32'; 'ident' was provided

$ cx genetic-programming-example.cx
genetic-programming-example.cx:25: syntax error: unexpected IDENTIFIER


$ cx intro-typespecific.cx
error: intro-typespecific.cx:6 function 'print' not found in package 'main'

$ cx pointers-example-1.cx
error: pointers-example-1.cx:15 function 'makeCells' not found in package 'main'
error: pointers-example-1.cx:16 identifier 'glfw' does not exist

$ cx repr-function-redefinition.cx
error: repr-function-redefinition.cx:5 function redeclaration

$ cx serialization-declarations.cx
serialization-declarations.cx:19: syntax error: unexpected VAR

$ cx serialization-expression.cx
serialization-expression.cx:21: syntax error: unexpected VAR


$ cx serialization-memory.cx
serialization-memory.cx:7: syntax error: unexpected RBRACE

$ cx serialization-package.cx
serialization-package.cx:7: syntax error: unexpected RBRACE


$ cx serialization-program.cx
error: serialization-program.cx:8 function 'serialize' expected input argument of type 'aff'; '[]aff' was provided
error: serialization-program.cx:8 function 'serialize' expected receiving variable of type 'byte'; '[]byte' was provided

$ cx unittest-example.cx
error: unittest-example.cx:9 operator 'assert' expects to return 1 output, but 0 receiving arguments were provided

examples/data-structures/

$ cx structs.cx
error: structs.cx:21 'p' redeclared

examples/opengl

$ cx bouncing-ball-control.cx
panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cxgo/actions.ShorthandExpression(0xc00000e6d8, 0x1, 0x1, 0xc00000e718, 0x1, 0x1, 0x9, 0x1, 0x1, 0xc0000b04c0)
	/home/amherag/go/src/github.com/skycoin/cx/cxgo/actions/expressions.go:288 +0x4f6
github.com/skycoin/cx/cxgo/parser.yyParse(0xe88ac0, 0xc0000d8550, 0xc0000d8550)
	/home/amherag/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:2140 +0x6eaf
github.com/skycoin/cx/cxgo/parser.Parse(0xc0000d8550, 0xc0001da000)
	/home/amherag/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:18 +0x37
main.main()
	/home/amherag/go/src/github.com/skycoin/cx/cxgo/main.go:779 +0xf07

$ cx conways-game-of-life.cx
error: conways-game-of-life.cx:225 function 'gl.BufferData' expected input argument of type '[]f32'; '[18]f32' was provided
error: conways-game-of-life.cx:227 'vao' redeclared

$ cx conways-game-of-life-gc.cx
error: conways-game-of-life-gc.cx:223 function 'gl.BufferData' expected input argument of type '[]f32'; '[18]f32' was provided
error: conways-game-of-life-gc.cx:225 'vao' redeclared

$ cx draw-elements.cx
error: draw-elements.cx:192 field '*lcl_30' not found in struct 'Block'
error: draw-elements.cx:192 field '*lcl_30' not found in struct 'Block'
error: draw-elements.cx:191 function 'f32.sub' expected input argument of type 'f32'; '' was provided

$ cx smooth-motion-control.cx
error: smooth-motion-control.cx:201 operands are not of the same type

examples/serialization/

$ cx example.cx
error: example.cx:2 

examples/affordances/

ALL AFFORDANCE EXAMPLES FAIL WITH FOLLOWING ERRORS:

error: argument-expression.cx:17 cannot assign value of type '[]aff' to identifier 'tgt' of type 'aff'
error: argument-expression.cx:21 cannot assign value of type '[]aff' to identifier 'fltrs' of type 'aff'

"break" exits all(?) outer "for loops"

@corpusc commented on Jul 26

To Reproduce

  1. use the following code:

package main

func main() {
for h := 0; h < 5; h++ {
for i := 0; i < 5; i++ {
for j := 0; j < 5; j++ {
break
printf("j: %d \n", j)
}

  str.print("out of j loop")
}

str.print("out of i loop")

}

str.print("out of h loop")
}

  1. notice only the last print "out of h loop" happens

Expected behavior

all 3 "out of _" print statements should be run. j, i then h.

Desktop (please complete the following information):

  • OS: Windows 10
  • CX Version: 0.7.0 full release

cx chains read() error & printf() fails in counter

@0pcom commented on Jun 12

Desktop (please complete the following information):

  • OS: ArchLinux 4.19.46-1-lts x86_64
  • CX Version 0.7beta+
  • CX Version 0.7.1

Describe the bug
read() causes errors in cx chains

To Reproduce

initialize the following cx chains application (per the cx chains tutorial) to test read()

$ cat message-txn.cx
package main
import "bc"

func main() {
	bc.incChatter()
}

$ cat message-bc.cx
package bc

var msg str
func incChatter() {
  msg = read()
}

package main
func main () {
}

broadcast a transaction:

$ cx --secret-key $SECRET_KEY --broadcast message-txn.cx

panic: Post http://127.0.0.1:6421/api/v1/wallet/transaction: EOF

goroutine 1 [running, locked to thread]:
main.main()
	/home/user/go/src/github.com/skycoin/cx/cxgo/main.go:952 +0x5ca7

The peer node starts giving errors at this point and must be restarted

Expected behavior
transaction completes without error

Compilation error when using return value of len function in short hand expression.

@asahi3g commented on Jul 3

To Reproduce

package main

func main()() {
	var s[]str
	s = append(s, "33")
	i := len(s)
	test(i, 1, "")
	test(s[0], "33", "")
}

Expected behavior
No compilation error and test pass.

Screenshots

error: pending_11.cx:6 function 'len' expected receiving variable of type 'i32'; 'str' was provided
error: pending_11.cx:11 first and second input arguments' types are not equal in 'test' call ('str' != 'i32')

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

Slice append broken in cx 0.7.1

@0pcom commented on Aug 3

Desktop:

  • OS: Linux
  • CX Version 0.7.1 (+opengl)

I am using the latest version of CX compiled from source with make build-full for opengl support

Describe the bug

In testing the whacky stack game I noticed an error which occurs with cx 0.7.1
This error is not present in previous cx versions; and the game works successfully with cx 0.7.0.

error: menu.cx:63, CX_RUNTIME_SLICE_INDEX_OUT_OF_RANGE, 9

Here is the link to the menu.cx file which the error is referring to

The error message is pointing to the last line here:

func makeMenuItem(menuId i32, size f32, text str) {
 	var mIt MenuItem 
 	mIt = MenuItem{ Size: size, Text: text }
 	Items[menuId] = append(
	Items[menuId], mIt)
}

To Reproduce

Compile CX 0.7.1 with opengl
from the skycoin/cx folder:
make build-full
clone the cx games repo

git clone https://github.com/skycoin/cx-games
cd cx-games/whacky-stack

run the game with cx 0.7.1 and 0.7.0
cx .
Expected behavior
error should not be there

strange error messages for missing right parenthesis (or curly brace)

@corpusc commented on Jun 4

Describe the bug

although this is a bottom priority thing, and it is fairly obvious what the problem is in my example code,... when you have a long/complex line/expression, it can take awhile to figure out what the problem is, when the error refers to characters that may not be present in the line/expression. which is what happened to me. :) and CX code is heavy with parentheses pairs with all the longhand expressions currently needed (for reliability).

To Reproduce

  1. use the following code:
    package main

var sl []i32 = []i32{1,2,3}

func main () {
printf("len: %d", len(sl)
}

  1. now delete the the right curly brace from line 3, for the same error message (pointing to different line).

  2. now reduce line 6 to just "printf(" and you get a DIFFERENT wrong error message:
    "unexpected RBRACE"

Expected behavior

i would like the error to mention that a matching right parenthesis (or curly brace) is needed.

Desktop

  • OS: Windows 10
  • CX Version 0.7beta

1-liner init gives no error OUTSIDE of funcs (but remains empty) - study with 437 & 438

@corpusc commented on Jul 3

To Reproduce

  1. Use code:

package main

type Color3 struct {
R f32
G f32
B f32
}

func main() {
var colors []Color3 = []Color3{ Color3{R: 1.0, G: 1.0, B: 1.0} }
i32.print(len(colors))
}

Observe error, then move the "var colors" line OUTSIDE of func, to see it run with no error. But notice the slice remains empty.
Expected behavior
To work both inside and outside of funcs.

Screenshots

error: c.cx:10 identifier 'Color3' does not exist
error: c.cx:10 field 'R' in struct literal of type 'Color3' expected argument of type 'Color3'; 'f32' was provided
error: c.cx:10 cannot assign value of type 'f32' to identifier 'R' of type ''
error: c.cx:10 identifier 'Color3' does not exist
error: c.cx:10 field 'G' in struct literal of type 'Color3' expected argument of type 'Color3'; 'f32' was provided
error: c.cx:10 cannot assign value of type 'f32' to identifier 'G' of type ''
panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cxgo/actions.CheckTypes(0xc000062e60)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:620 +0x10b6
github.com/skycoin/cx/cxgo/actions.FunctionDeclaration(0xc00006e5b0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0000660c0, 0x6, 0x8)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:166 +0x48f
github.com/skycoin/cx/cxgo/parser.yyParse(0x100cd60, 0xc0000aa000, 0xc0000aa000)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:1744 +0x1d40
github.com/skycoin/cx/cxgo/parser.Parse(0xc0000aa000, 0xc0001a8000)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:18 +0x3e
main.main()
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/main.go:826 +0xf52

Desktop:

  • OS: Windows 10
  • CX Version 0.7.0 full release

using "break" outside structures it's intended for, should warn user

@corpusc commented on Jul 26

Description

This could be at the very bottom of the priority list, as far as importance?
However it seems like it could be any easy side-fix when #452 gets fixed.

When I started making Issue #452, I tried making a code sample that was as simple as possible.
When you run this, every single print gets executed and shown:

package main

func main() {
if true {
if true {
if true {
break
printf("after break \n")
}

		str.print("hm")
	}
	
	str.print("hmm")
}

str.print("hmmm")
}

This got me curious about the break keyword, since I believe I've only tried it within
for loops. When looking at C# documentation, it seems it was only designed to be used within for loops and switch blocks. I assume it's probably the same for most C-like languages, so this sample apparently works fine, except for a lack of warning.

Expected behavior

CX should point to the file and line # where any incorrectly used "break" keyword is, and warn that it should only be used in the cases that CX expects.

Desktop:

  • OS: Windows 10
  • CX Version 0.7.0 full release

Compilation error when using return value of a method call in an inline initialization

@asahi3g commented on May 10

Describe the bug
Compilation error when using return value of a method call in an inline ititialization

To Reproduce

package main
type too struct {
}
func (t *too)foo()(b bool) {
	b = true
}
func main()() {
	var t too
	var b bool = t.foo()
}

Expected behavior
No compilation error

Screenshots

error: pending_4.cx:12 't' has no fields
error: pending_4.cx:12 trying to assign argument of type 'ident' to symbol 'b' of type 'bool'
error: pending_4.cx:12 cannot assign value of type 'ident' to identifier 'b' of type 'bool'

Desktop (please complete the following information):

OS: linux
CX Version 0.6.2 commit 4ba0d2d
Additional context
No compilation error when return value is not use in an inline initialization

package main
type too struct {
}
func (t *too)foo()(b bool) {
	b = true
}
func main()() {
	var t too
	var b bool
	b = t.foo()
}

specify the version of the binaries used

@4rchim3d3s commented on Aug 13

Is your feature request related to a problem? Please describe.
It's not really a problem, but could be easier to track which cx binary version i use while debugging and testing

Describe the solution you'd like
when pressing cx -v you get back the version number like that:

CX version 0.7.1
Something like this would be nice:
For self compiled:

CX version 0.7.1
Selfbuild - BuildDate - BuildTime

Or for offical binary releases

CX version 0.7.1
Official - ReleaseDate

Runtime error when calling str.i32 with a string not representing a valid i32 number.

@asahi3g commented on Jul 3

To Reproduce

package main
func main()() {
	i := str.i32("a")
	k := str.i32("-2147483649")
}

Expected behavior
Parsing methods (str.*) should return an error on failure.

Screenshots

error: pending_12.cx:4, CX_RUNTIME_ERROR, 
===Callstack===
>>> main()
Expressions
 	pending_12.cx:4 : str.i32() : 0
	pending_12.cx:5 : str.i32() : 0

goroutine 1 [running, locked to thread]:
runtime/debug.Stack(0x2a, 0x0, 0x0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/skycoin/cx/cx.runtimeErrorInfo(0xcece40, 0xfb2cf0, 0xfb2c01, 0x5)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/utilities.go:836 +0x2c1
github.com/skycoin/cx/cx.RuntimeError()
	/home/cxfx/go/src/github.com/skycoin/cx/cx/utilities.go:859 +0x16d
panic(0xcece40, 0xfb2cf0)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/skycoin/cx/cx.opStrStr(0xc0000928c0, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/op_str.go:27 +0x4d1
github.com/skycoin/cx/cx.init.2.func1(0xc00019c0f0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/opcodes_core.go:1302 +0x6dd
github.com/skycoin/cx/cx.init.3.func1(0xc00019c0f0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/opcodes_extra.go:594 +0xfc3
github.com/skycoin/cx/cx.(*CXCall).ccall(0xc0002ea000, 0xc00019c0f0, 0x0, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:278 +0x331
github.com/skycoin/cx/cx.(*CXProgram).Run(0xc00019c0f0, 0xe3ef01, 0xc000199250, 0xffffffffffffffff, 0x0, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:118 +0x126
github.com/skycoin/cx/cx.(*CXProgram).RunCompiled(0xc00019c0f0, 0x0, 0x0, 0x0, 0x0, 0xc000080750, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:200 +0x231
main.main()
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/main.go:1003 +0x24c3

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

ambiguous referencing same-named funcs from imported packages

@0pcom commented on Aug 9

Describe the bug

A cx program is defined which contains reference to functions with the same name from imported packages:

package main


import "foo"
import "bar"
import "xyzzy"

func main () {
xyzzy.testprint()
}

package foo

func test1 () {
str.print("Hello World!")
}

package bar

func test1 () {
str.print("Goodbye World!")
}

package xyzzy
import "main"

func testprint () {
main.test1()
}

The result of this program depends on the order the packages are imported

This is non-desireable or ambiguous behavior

To Reproduce
run the above program

Expected behavior
The program should probably display an error in the case that a func (rather, a pointer to a func name) is redefined by a subsequently imported package.

In lieu of that, It might be better if it was required to directly reference a package function, rather than just referencing main or another package which has already imported the requisite packages.

Desktop

  • OS: Linux
  • CX Version 0.7.1

Additional context

This behavior is different for vars than funcs

package main

import "bar"
import "foo"
import "xyzzy"

func main () {
xyzzy.testprint()
}

package foo
var string1 str = "Hello World!"

package bar
var string1 str = "Goodbye World!"

package xyzzy
import "main"

func testprint () {
str.print(sprintf("String 1: %s", main.string1))
}

when run gives:
panic: struct 'string1' not found in package 'main'

it appears while vars must be directly referenced, funcs can be referenced by proxy (i.e. referencing a package which has imported a package containing the func)

PANIC index out of range, FIXED by moving an if {} block

@corpusc commented on Jun 21

Description
Strangely enough, simply rearranging the same code can fix this example, so it compiles.

To Reproduce
Steps to reproduce the behavior:

  1. use following code:
    package main

func main() {
foo()
bar()
}

func foo() {
if cat() {
for i := 0; i < 4; i++ {
}

if cat() {
}

}

if cat() {
}
}

func bar() {
}

func cat() (b bool) {
}

...and you will get the panic.

  1. Simply MOVE the "if cat() {}" from the bottom of foo() into empty func bar(). FIXED!
  2. BONUS weirdness & hopefully a hint....Now undo that change, so bar() is empty again.
  3. Now DELETE the for loop. FIXED! Even tho it's a legit for loop by itself

Expected behavior
I certainly wouldn't expect for the EXACT same code and flow to cause errors unless i break it up into more funcs than I actually wanted.
My original code was WAY more complex, but I was able to give you a stripped to the bone, thin skeleton, that still exhibited the same strangeness.

Error text
panic: runtime error: index out of range

goroutine 1 [running, locked to thread]:
github.com/skycoin/cx/cxgo/actions.GetGlobalSymbol(0xc000086ac8, 0xc00030e2d0, 0xc00099d5a0, 0x13)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:1147 +0x17d
github.com/skycoin/cx/cxgo/actions.UpdateSymbolsTable(0xc000086ac8, 0xc000949320, 0xc000086a88, 0x1)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:727 +0x3fe
github.com/skycoin/cx/cxgo/actions.ProcessExpressionArguments(0xc000086ac8, 0xc000086aa0, 0xc000086a88, 0xc00006edd0, 0xc0000521b0, 0x2, 0x2, 0xc000ae6b40, 0x445701)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:374 +0x458
github.com/skycoin/cx/cxgo/actions.FunctionDeclaration(0xc00006edd0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000398200, 0x18, 0x20)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/actions/functions.go:142 +0x390
github.com/skycoin/cx/cxgo/parser.yyParse(0x100cd60, 0xc0000aa870, 0xc0000aa870)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:1744 +0x1d40
github.com/skycoin/cx/cxgo/parser.Parse(0xc0000aa870, 0xc0001a8000)
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/parser/cxgo.go:18 +0x3e
main.main()
C:/Users/Amaury/go/src/github.com/skycoin/cx/cxgo/main.go:826 +0xf52

Desktop:

  • OS: Windows 10
  • CX Version 0.7.0 full release

"os" package not functioning correctly

@0pcom commented on Jun 18

Describe the bug

When the following code is run, nothing is printed.
It doesn't like anything inside the parentheses either.

To Reproduce

package main
import "os"

func main () {
  var wd str
  wd = os.GetWorkingDirectory()
str.print(wd)
}

Expected behavior
I assume it should be putting something into var wd and print it back to the screen.

System:

  • OS: Archlinux
  • 0.7beta

Additional Context

The other os functions don't seem to work correctly either;

os.Open()
os.Close()

else their documentation is missing something.

Panic when trying to print a negative literal as a string with printf.

@asahi3g commented on Jul 3

To Reproduce

package main

func main()() {
	printf("%s\n", -1)
	panic(true, false, "must not compile")
}

Expected behavior
Compilation error eg golang:
Printf format %s has arg -1 of wrong type int
Ideally this should be done at compile time when the format string is a literal.

Screenshots

error: pending_10.cx:4, CX_RUNTIME_ERROR, runtime error: slice bounds out of range
===Callstack===
>>> main()
Expressions
 	pending_10.cx:5 : neg() : -1

goroutine 1 [running, locked to thread]:
runtime/debug.Stack(0x52, 0x0, 0x0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/skycoin/cx/cx.runtimeErrorInfo(0xd78be0, 0x15cbcc0, 0x15cbc01, 0x5)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/utilities.go:836 +0x2c1
github.com/skycoin/cx/cx.RuntimeError()
	/home/cxfx/go/src/github.com/skycoin/cx/cx/utilities.go:859 +0x16d
panic(0xd78be0, 0x15cbcc0)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/skycoin/cx/cx.ReadStr(0x0, 0xc000169e60, 0xc000669807, 0x3)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/op.go:472 +0x2c2
github.com/skycoin/cx/cx.buildString(0xc000092140, 0x0, 0xc000032000, 0xeaa200, 0xc000198f48)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/op_und.go:494 +0x965
github.com/skycoin/cx/cx.opPrintf(0xc000092140, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/op_und.go:561 +0x39
github.com/skycoin/cx/cx.init.2.func1(0xc00061e000)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/opcodes_core.go:985 +0x324
github.com/skycoin/cx/cx.init.3.func1(0xc00061e000)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/opcodes_extra.go:594 +0xfc3
github.com/skycoin/cx/cx.(*CXCall).ccall(0xc0002ec000, 0xc00061e000, 0x0, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:278 +0x331
github.com/skycoin/cx/cx.(*CXProgram).Run(0xc00061e000, 0xe3ef01, 0xc000199250, 0xffffffffffffffff, 0x0, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:118 +0x126
github.com/skycoin/cx/cx.(*CXProgram).RunCompiled(0xc00061e000, 0x0, 0x0, 0x0, 0x0, 0xc000082680, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:200 +0x231
main.main()
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/main.go:1003 +0x24c3

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

Array literals: Problem with temporary variables in multi-dimensional arrays.

@amherag commented on Sept 11

Describe the bug
Considering the following code:

var i [3][2]i32

var a [2]i32
var b [2]i32
var c [2]i32

a = [2]i32{1,2}
b = [2]i32{30,40}
c = [2]i32{500,600}

i = [3][2]i32{a, b, c}

which generates the following (partial) abstract syntax tree (AST):

17.- Expression: *tmp_6[0] [2]i32 = identity(a [2]i32)
18.- Expression: *tmp_6[1] [2]i32 = identity(b [2]i32)
19.- Expression: *tmp_6[2] [2]i32 = identity(c [2]i32)
20.- Expression: i [3][2]i32 = identity(*tmp_6 [2]i32)

*tmp_6 (a temporary variable created by the parser) has the correct indexing, but the parser is not declaring it with the correct type. It is ignoring the indexes of i (instead of creating a matrix is is creating a vector).

To Reproduce
In order to reproduce this problem, CX needs to include the changes presented in PR #479 to see the same AST. If this PR has not been merged, test the code below by git checkouting the branch used in that PR. Steps to reproduce the behavior:

  1. Type in the following code in a test.cx file:
package main

func main() {
	var i [3][2]i32

	var a [2]i32
	var b [2]i32
	var c [2]i32
	a = [2]i32{1,2}
	b = [2]i32{30,40}
	c = [2]i32{500,600}

	i = [3][2]i32{
		a, b, c}
}
  1. Run the source file with cx -r test.cx
  2. Run the CX meta-command :dp to display the AST.

Expected behavior
The parser should create the temporary variables involved in the creation of an array literal with the correct types (which include the dimensions declared for i).

Desktop (please complete the following information):

  • OS: Linux, Debian.
  • CX from branch in PR #479 .

No compilation error when global variable is redeclared at local scope.

@asahi3g commented on May 10

Describe the bug
Variable declared at global scope can be redeclared at local scope without compilation error.

To Reproduce

package main
var i i32 = 55
func main()() {
	var i i32 = 44
	panic(true, false, "must not compile")
}

Expected behavior
Compilation error stating i is redeclared

Desktop (please complete the following information):

  • OS: linux
  • CX Version 0.6.2 commit 4ba0d2d

Additional context
Add any other context about the problem here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.