Skip to content

Commit

Permalink
jj2repl
Browse files Browse the repository at this point in the history
  • Loading branch information
SpazElectro committed Sep 7, 2024
1 parent 35afc58 commit 1e16b7f
Show file tree
Hide file tree
Showing 21 changed files with 915 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{
"recommendations": [
"shd101wyy.markdown-preview-enhanced",
"christian-kohler.path-intellisense",
"esbenp.prettier-vscode",
"michelemelluso.gitignore",
"ms-python.vscode-pylance",
"ms-vscode.cpptools",
"ms-dotnettools.csdevkit"
]
}
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"C_Cpp.errorSquiggles": "disabled",
"files.associations": {
"*.mut": "cpp",
"*.asc": "cpp",
Expand Down
Binary file added experiments/jj2repl/bin/main_debug.exe
Binary file not shown.
Binary file added experiments/jj2repl/bin/main_release.exe
Binary file not shown.
14 changes: 14 additions & 0 deletions experiments/jj2repl/bin/script.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int vroom() {
return 2;
}

void main() {
int sum1 = Add(1, 2);
double sum2 = Add(1.5, 2.5);
int sum3 = Add(1, 2, 3);

auto a = Add(2, 3);

Print("Sum1: " + sum1 + ", Sum2: " + sum2 + ", Sum3: " + sum3);
Print(""+vroom());
}
1 change: 1 addition & 0 deletions experiments/jj2repl/classes.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions experiments/jj2repl/classes_unstripped.json

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions experiments/jj2repl/codegen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import json

OUTPUT = """// This file was automatically generated. Do not modify.
#include "funcs.h"
// Typedefs
typedef uint8_t byte;
typedef int8_t int8;
typedef uint8_t uint8;
typedef int16_t int16;
typedef uint16_t uint16;
typedef int32_t int;
typedef uint32_t uint;
typedef float float32;
typedef int64_t int64;
typedef uint64_t uint64;
typedef double double64;
%DEFINE_FUNCTIONS%
void RegisterFunctions(asIScriptEngine* engine) {
%REGISTER_FUNCTIONS%
}
"""

f = open("global.json").read()
f = json.loads(f)

define_functions = ""
register_functions = ""

# actual codegen goes here

funcs = f["globalfunctionsList"]
for x in funcs:
returns = "0"
return_type = x["full"].split(x["name"])[0].strip()
if return_type == "bool":
returns = "true"
elif return_type == "void":
returns = ""
elif return_type == "float":
returns = "0.0"
elif return_type == "string":
returns = "\"\""
elif return_type != "int" and return_type != "uint16" and return_type != "uint64" and return_type != "uint":
print(f"IDK what this is {return_type}")

define_functions += x["full"] + " {\n"
define_functions += f"\treturn {returns};\n"
define_functions += "}\n\n"

# engine->RegisterGlobalFunction("int Add(int, int)", asFUNCTION(Add), asCALL_CDECL);

register_functions += f"\tengine->RegisterGlobalFunction(\"{x['full']}\", asFUNCTION({x['name']}), asCALL_CDECL);\n"
# codegen end

OUTPUT = OUTPUT.replace("%DEFINE_FUNCTIONS%", define_functions).replace(
"%REGISTER_FUNCTIONS%", register_functions
)
open("output.cpp", "w").write(OUTPUT)
1 change: 1 addition & 0 deletions experiments/jj2repl/global.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions experiments/jj2repl/global_unstripped.json

Large diffs are not rendered by default.

Loading

0 comments on commit 1e16b7f

Please sign in to comment.