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

[WIP] Nim Compiler #170

Merged
merged 5 commits into from
Sep 15, 2019
Merged

[WIP] Nim Compiler #170

merged 5 commits into from
Sep 15, 2019

Conversation

sealmove
Copy link
Member

@sealmove sealmove commented Sep 11, 2019

meta:
  id: hello_world
seq:
  - id: one
    type: u1
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import ../../runtime/nim/kaitai

type
  HelloWorld* = ref object
    one*: uint8
    root*: HelloWorld
    parent*: ref RootObj

proc read*(_: typedesc[HelloWorld], stream: KaitaiStream, root: HelloWorld, parent: ref RootObj): owned HelloWorld =
  result = new(HelloWorld)
  let root = if root == nil: result else: root
  result.one = readU1(stream)
  result.root = root
  result.parent = parent

proc fromFile*(_: typedesc[HelloWorld], filename: string): owned HelloWorld =
  var stream = newKaitaiStream(filename)
  HelloWorld.read(stream, nil, nil)

I think this pattern is flexible and neat:

  • The user will be able to create objects of any type (subsections of a format) by simply providing the type and a file path (fromFile()). In this case the object returned will be a root object. For example he will be able to create a Png Chunks object like this: Chunks.fromFile("path/to/partial/file")
  • read() is mostly for internal use, but it's also exposed to the user in case he needs to do something more involved (for example construct a png from partial png files).

@sealmove sealmove changed the title hello_world.ksy compiles correctly make hello_world.ksy compile correctly (WIP) Sep 11, 2019
@sealmove sealmove changed the title make hello_world.ksy compile correctly (WIP) Nim Compiler (WIP) Sep 11, 2019
@sealmove sealmove changed the title Nim Compiler (WIP) [WIP] Nim Compiler Sep 13, 2019
@sealmove
Copy link
Member Author

hello_world.ksy now compiles correctly!
The basic architecture for Nim compiler is now set up.
Next step is to write all the tests.


override def fileHeader(topClassName: String): Unit = {
outHeader.puts(s"# $headerComment")
importList.add(s"../../../runtime/nim/kaitai")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this refers to the location of these files in test repo vs runtimes repo, but it won't be always true for production use?

Copy link
Member Author

@sealmove sealmove Sep 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed RuntimeConfig.scala and the relevant command line options (which exist for only ~half of the supported languages) but I am a little unsure about the approach here. Is it safe to say that it's simply a matter of having a saner default and adding a command line option for specifying the module's path?

Proposal:

  • default = "kaitai" (root folder of user's project)
  • command line option = --nim-runtime-path

@GreyCat
Copy link
Member

GreyCat commented Sep 15, 2019

Looks good to me, thanks for this contribution! Merging in.

@GreyCat GreyCat merged commit 0ec4d52 into kaitai-io:master Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants