Skip to content

Commit

Permalink
Workaround nim-lang/Nim#16664
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jan 10, 2021
1 parent 10236e9 commit fe82c68
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions flambeau.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export serialize
# C++ Standard Library
# ----------------------------------------------------------------

import ./flambeau/cpp/std_cpp
export std_cpp
import ./flambeau/cpp/[std_cpp, emitters]
export std_cpp, emitters

# Convenience helpers
# ----------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions flambeau/cpp/emitters.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Special emit - https://github.com/nim-lang/Nim/blob/acf3715/compiler/ccgstmts.nim#L1489-L1495

template emitTypes*(typesection: static string): untyped =
## Emit a C/C++ typesection
{.emit: "/*TYPESECTION*/\n" & typesection.}

template emitGlobals*(globals: static string): untyped =
## Emit a C/C++ global variable declaration
{.emit: "/*VARSECTION*/\n" & globals.}

template emitIncludes*(includes: static string): untyped =
## Emit a C/C++ global variable declaration
{.emit: "/*INCLUDESECTION*/\n" & includes.}
18 changes: 13 additions & 5 deletions proof_of_concepts/poc09_end_to_end.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import
../flambeau,
std/[enumerate, strformat]

# Net is defined in poc_09_end_to_end_types.nim.hpp
# to work around https://github.com/nim-lang/Nim/issues/16664
# which workarounds https://github.com/nim-lang/Nim/issues/4687
# Inline C++
# workaround https://github.com/nim-lang/Nim/issues/16664
# and workaround https://github.com/nim-lang/Nim/issues/4687

emitTypes:
"""
struct Net: public torch::nn::Module {
torch::nn::Linear fc1{nullptr};
torch::nn::Linear fc2{nullptr};
torch::nn::Linear fc3{nullptr};
};
"""

type Net
{.pure, importcpp,
header:"poc09_end_to_end_types.nim.hpp".}
{.pure, importcpp.}
= object of Module
fc1: Linear
fc2: Linear
Expand Down
22 changes: 0 additions & 22 deletions proof_of_concepts/poc09_end_to_end_types.nim.hpp

This file was deleted.

0 comments on commit fe82c68

Please sign in to comment.