Start writing interface implementation generation

This commit is contained in:
2021-10-12 12:30:38 -06:00
parent 050af36dc9
commit cc32376474

View File

@@ -3,6 +3,7 @@ package kiss;
import sys.io.Process; import sys.io.Process;
#if macro #if macro
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.macro.Context;
import kiss.Kiss; import kiss.Kiss;
import kiss.Reader; import kiss.Reader;
import kiss.Stream; import kiss.Stream;
@@ -27,13 +28,28 @@ class Main {
static macro function macroMain():Expr { static macro function macroMain():Expr {
var args = Sys.args(); var args = Sys.args();
// TODO `kiss run` subcommand with optional target option. With no target specified, keep trying targets until one exits with status 0 (side-effect danger)
switch (args.shift()) { switch (args.shift()) {
case "convert": case "convert":
convert(args); convert(args);
case "new-project": case "new-project":
newProject(args); newProject(args);
case "implement":
// kiss implement [type] [fromLib]
var _pwd = args.pop();
var theInterface = args.shift();
var pArgs = ["build-scripts/common-args.hxml", "-lib", "kiss"];
// pass --lib and the lib containing the interface as specified
if (args.length > 0) {
pArgs = pArgs.concat(["-lib", args.shift()]);
}
pArgs = pArgs.concat(["--run", "kiss.Main", "_implement", theInterface]);
var p = new Process("haxe", pArgs);
var exitCode = p.exitCode(true);
Sys.print(p.stdout.readAll().toString());
Sys.print(p.stderr.readAll().toString());
Sys.exit(exitCode);
case "_implement":
implement(args[0]);
case other: case other:
// TODO show a helpful list of subcommands // TODO show a helpful list of subcommands
Sys.println('$other is not a kiss subcommand'); Sys.println('$other is not a kiss subcommand');
@@ -112,7 +128,6 @@ class Main {
// with --all, it reads everything from stdin at once (for piping). Without --all, it acts as a repl, // with --all, it reads everything from stdin at once (for piping). Without --all, it acts as a repl,
// where \ at the end of a line signals that the expression is not complete // where \ at the end of a line signals that the expression is not complete
// TODO write tests for this // TODO write tests for this
// TODO use this to implement runAtRuntime() for sys targets by running a haxe subprocess
#if macro #if macro
var k = Kiss.defaultKissState(); var k = Kiss.defaultKissState();
k.wrapListExps = false; k.wrapListExps = false;
@@ -159,4 +174,11 @@ class Main {
} }
#end #end
} }
static function implement(theInterface:String) {
#if macro
var type = Context.resolveType(Helpers.parseComplexType(theInterface), Context.currentPos());
trace(type);
#end
}
} }