Commit e95712ca1830ecec1fff3315b049ed587905c17e

Authored by Andreas Rumpf
1 parent 01dbfa89

bugfixes and cleanups

src/squeaknim.nim
@@ -38,6 +38,7 @@ template writeSmallTalkCode*(filename: string) = @@ -38,6 +38,7 @@ template writeSmallTalkCode*(filename: string) =
38 writeFile(filename, stCode) 38 writeFile(filename, stCode)
39 39
40 proc mapTypeToC(symbolicType: NimNode): string {.compileTime.} = 40 proc mapTypeToC(symbolicType: NimNode): string {.compileTime.} =
  41 + if symbolicType.kind == nnkEmpty: return "void"
41 let t = symbolicType.getType 42 let t = symbolicType.getType
42 if symbolicType.kind == nnkSym and t.typeKind == ntyObject: 43 if symbolicType.kind == nnkSym and t.typeKind == ntyObject:
43 return gPrefix & $symbolicType 44 return gPrefix & $symbolicType
@@ -46,6 +47,7 @@ proc mapTypeToC(symbolicType: NimNode): string {.compileTime.} = @@ -46,6 +47,7 @@ proc mapTypeToC(symbolicType: NimNode): string {.compileTime.} =
46 expectKind t, nnkBracketExpr 47 expectKind t, nnkBracketExpr
47 result = mapTypeToC(t[1]) & "*" 48 result = mapTypeToC(t[1]) & "*"
48 of ntyCString: result = "char*" 49 of ntyCString: result = "char*"
  50 + of ntyPointer: result = "void*"
49 of ntyInt: result = intType 51 of ntyInt: result = intType
50 of ntyInt8: result = "sbyte" 52 of ntyInt8: result = "sbyte"
51 of ntyInt16: result = "short" 53 of ntyInt16: result = "short"
@@ -61,7 +63,7 @@ proc mapTypeToC(symbolicType: NimNode): string {.compileTime.} = @@ -61,7 +63,7 @@ proc mapTypeToC(symbolicType: NimNode): string {.compileTime.} =
61 of ntyBool, ntyChar, ntyEnum: result = "char" 63 of ntyBool, ntyChar, ntyEnum: result = "char"
62 else: quit "Error: cannot wrap to Squeak " & treeRepr(t) 64 else: quit "Error: cannot wrap to Squeak " & treeRepr(t)
63 65
64 -macro exportSt*(className: string; body: stmt): stmt = 66 +macro exportSt*(body: stmt): stmt =
65 # generates something like: 67 # generates something like:
66 68
67 # system: aString 69 # system: aString
tests/Test1.nim
@@ -3,7 +3,7 @@ import squeaknim @@ -3,7 +3,7 @@ import squeaknim
3 3
4 # Just compile with "nim c Test1.nim", copy resulting lib and Test1.st 4 # Just compile with "nim c Test1.nim", copy resulting lib and Test1.st
5 # to a Squeak directory, file in Test1.st and then it should be fine 5 # to a Squeak directory, file in Test1.st and then it should be fine
6 -# to call foo, see class side of Test1 6 +# to call foo, see class side of Test1
7 7
8 type 8 type
9 MyFloat = float32 9 MyFloat = float32
@@ -18,13 +18,13 @@ setModulename "Test1", "UR" @@ -18,13 +18,13 @@ setModulename "Test1", "UR"
18 # Generate the Smalltalk class URVector3 representing Vector3 18 # Generate the Smalltalk class URVector3 representing Vector3
19 wrapObject(Vector3) 19 wrapObject(Vector3)
20 20
21 -# Generate declarations for Smalltalk code 21 +# Generate declarations for Smalltalk code
22 writeExternalLibrary() 22 writeExternalLibrary()
23 23
24 # Here follows Nim procedures that will be callable via FFI 24 # Here follows Nim procedures that will be callable via FFI
25 # Note that exportSt pragma to export. 25 # Note that exportSt pragma to export.
26 26
27 -proc foo*(a, b: Vector3, c: int): cstring {.exportSt: "bar".} = 27 +proc foo*(a, b: Vector3, c: int): cstring {.exportSt.} =
28 # Just a silly test proc 28 # Just a silly test proc
29 result = "x plus y plus c " & $(a.x + b.y + c.float) 29 result = "x plus y plus c " & $(a.x + b.y + c.float)
30 30