Skip to content

Language: header declaration (a function of another file) #44

Closed

Description

@Solype

A program cannot be split into several files yet: the compiler takes several .kr (compiler -x a.kr b.kr), but each one must have its own main (lib.kr:1:1: the program has no main), and a file cannot call a function of another one.

To call a function defined in another file, the current file needs a declaration of it without a body, a header:

정수를 반환하는 더하다(정수 가, 정수 나)

Design

외부 stays for the libc; a function without a body and without 외부 is a Krc function defined elsewhere.

Declaration Name Symbol
외부 정수를 반환하는 printf(문자 주소 형식, …) latin C, the name as is
정수를 반환하는 더하다(정수 가) { … } verb in 다 Krc, mangled: 더하다$int
정수를 반환하는 더하다(정수 가) verb in 다 Krc, mangled: defined in another file
main the only latin name with a body C

To do

  • Grammar: Function → FunctionHead ( Parameters ) without a Block. After the ), a { starts the body, anything else ends the declaration; check that the LR(1) table has no conflict (see Parser: report LR(1) conflicts and expected tokens #22: conflicts are not reported yet)
  • Function (src/parser/postparser/structs.rs): a field such as external: bool, since no body no longer means libc
  • Decide the symbol from external || name == "main", not from body.is_none(), in the three places that do it today:
  • Only one file may have main; the others are libraries
  • A header and the definition of the same function in one file: decide (allowed and checked against each other, or refused)
  • Samples with two files: a call through a header, a header whose types differ from the definition (link error or check)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    converterSemantic checks and typed IR (src/converter)enhancementNew feature or requestfront-endLexer, pre-parser, parser, AST

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions