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

Custom label level types #36

Open
HuseyinSimsek7904 opened this issue Jan 10, 2024 · 0 comments
Open

Custom label level types #36

HuseyinSimsek7904 opened this issue Jan 10, 2024 · 0 comments
Assignees
Labels
compiler Anything about the compiler enhancement New feature or request quality-of-life Anything that focuses on making life easier

Comments

@HuseyinSimsek7904
Copy link
Member

HuseyinSimsek7904 commented Jan 10, 2024

Custom label level types can be useful to make sure that the xyz.init and xyz.end macros like sb.init and sb.end match. For example:

// '#block' must be ended with a '#endblock', otherwise the compiler will complain.
// This makes sure that 'sb.init' must be ended with a 'sb.end'.

// Create a string builder.
macro sb.init
  #block !!sb.block
  memory _sb.array_ sizeof(ptr) in
  memory _sb.ptr_   sizeof(ptr) in
    _sb.array_ _sb.ptr_ string-builder.init
endmacro

// Dump the contents to a stream and deallocate the string builder.
macro sb.end // file-desc: stream-to-dump
    let stream in
      // Dump the generated string.
      _sb.array_ _sb.ptr_ string-builder.to-array stream fputs

      // Deallocate the string builder object.
      _sb.array_ @64 mfree drop
    end
  end end
  #endblock !!sb.block
endmacro

// This is fine.
sb.init
  "hello, world!\n" sb.add-str
STDOUT sb.end

// This is not fine, `sb.end` ends `if`.
sb.init
  x 2 > if
  STDOUT sb.end
end
@HuseyinSimsek7904 HuseyinSimsek7904 added enhancement New feature or request compiler Anything about the compiler labels Jan 10, 2024
@HuseyinSimsek7904 HuseyinSimsek7904 self-assigned this Jan 10, 2024
@HuseyinSimsek7904 HuseyinSimsek7904 added the quality-of-life Anything that focuses on making life easier label Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Anything about the compiler enhancement New feature or request quality-of-life Anything that focuses on making life easier
Projects
None yet
Development

No branches or pull requests

1 participant