Crystal: Format bug: asm

Created on 26 Jun 2017  路  4Comments  路  Source: crystal-lang/crystal

dst = 0_u64
exit = 60_u64
asm("syscall" : "={rax}"(dst)
  : "{rax}"(exit), "{rdi}"(0)
  : "rcx", "r11", "memory"
  : "volatile")
$ crystal tool format algorithms/asm_print.cr
Error:, couldn't format 'algorithms/asm_print.cr',
please report a bug including the contents of it: https://github.com/crystal-lang/crystal/issues

Most helpful comment

@MakeNowJust I don't want to format asm :sweat_smile: but other code around :point_down:

class String
def to_unsafe
pointerof(@c)  # = > Can't be formatted because the bug
end
end

dst = 0_u64
exit = 60_u64
asm("syscall" : "={rax}"(dst)
  : "{rax}"(exit), "{rdi}"(0)
  : "rcx", "r11", "memory"
  : "volatile")

All 4 comments

@faustinoaq How do you want to format asm statement?

@MakeNowJust I don't want to format asm :sweat_smile: but other code around :point_down:

class String
def to_unsafe
pointerof(@c)  # = > Can't be formatted because the bug
end
end

dst = 0_u64
exit = 60_u64
asm("syscall" : "={rax}"(dst)
  : "{rax}"(exit), "{rdi}"(0)
  : "rcx", "r11", "memory"
  : "volatile")

There's asm used in the stdlib and the formatter doesn't fail, therefore there must be a bug in how the formatter in particular parses that asm because it uses more asm syntax than the stdlib does.

Currently crystal tool format formats asm with colon alignment, so I believe below is correct formatted code:

dst = 0_u64
exit = 60_u64
asm("syscall" : "={rax}"(dst)
              : "{rax}"(exit), "{rdi}"(0)
              : "rcx", "r11", "memory"
              : "volatile")

/cc @asterite

Was this page helpful?
0 / 5 - 0 ratings