refactor: extract IO class into separate module with wrenLoadIOLibrary and wren_io.c
Replace monolithic corelib.wren with per-class builtin/*.wren files and generate_builtins.py script. Move IO class definition and its native writeString_ method from wren_core.c to new wren_io.c, adding wrenGetArgumentString and wrenDefineStaticMethod to the public API. Update Makefile target from corelib to builtin and remove generate_corelib.py.
This commit is contained in:
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
import glob
|
||||
import os.path
|
||||
import re
|
||||
|
||||
PATTERN = re.compile(r'libSource =\n("(.|[\n])*?);')
|
||||
|
||||
def copy_builtin(filename):
|
||||
name = os.path.basename(filename)
|
||||
name = name.split('.')[0]
|
||||
|
||||
with open(filename, "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
wren_source = ""
|
||||
for line in lines:
|
||||
line = line.replace('"', "\\\"")
|
||||
line = line.replace("\n", "\\n\"")
|
||||
if wren_source: wren_source += "\n"
|
||||
wren_source += '"' + line
|
||||
|
||||
# re.sub() will unescape escape sequences, but we want them to stay escapes
|
||||
# in the C string literal.
|
||||
wren_source = wren_source.replace('\\', '\\\\')
|
||||
|
||||
constant = "libSource =\n" + wren_source + ";"
|
||||
|
||||
with open("src/wren_" + name + ".c", "r") as f:
|
||||
c_source = f.read()
|
||||
|
||||
c_source = PATTERN.sub(constant, c_source)
|
||||
|
||||
with open("src/wren_" + name + ".c", "w") as f:
|
||||
f.write(c_source)
|
||||
|
||||
print name
|
||||
|
||||
|
||||
for f in glob.iglob("builtin/*.wren"):
|
||||
copy_builtin(f)
|
||||
@@ -1,31 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import re
|
||||
|
||||
with open("corelib.wren", "r") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# Remove the comment from the top.
|
||||
lines.pop(0)
|
||||
lines.pop(0)
|
||||
|
||||
corelib = ""
|
||||
for line in lines:
|
||||
line = line.replace('"', "\\\"")
|
||||
line = line.replace("\n", "\\n\"")
|
||||
if corelib: corelib += "\n"
|
||||
corelib += '"' + line
|
||||
|
||||
with open("src/wren_core.c", "r") as f:
|
||||
wren_core = f.read()
|
||||
|
||||
# re.sub() will unescape escape sequences, but we want them to stay as escapes
|
||||
# in the C string literal.
|
||||
corelib = corelib.replace('\\', '\\\\')
|
||||
|
||||
corelib = "coreLibSource =\n" + corelib + ";"
|
||||
|
||||
PATTERN = re.compile(r'coreLibSource =\n("(.|[\n])*?);')
|
||||
wren_core = PATTERN.sub(corelib, wren_core)
|
||||
|
||||
with open("src/wren_core.c", "w") as f:
|
||||
f.write(wren_core)
|
||||
Reference in New Issue
Block a user