diff --git a/haxelib.json b/haxelib.json index 5ac51252..d6e82c2a 100644 --- a/haxelib.json +++ b/haxelib.json @@ -10,6 +10,7 @@ "classPath": "src/", "main": "kiss.Main", "dependencies": { - "hscript": "" + "hscript": "", + "utest": "" } } \ No newline at end of file diff --git a/src/build-scripts/common-args.hxml b/src/build-scripts/common-args.hxml index 93554eb4..8fe077c2 100644 --- a/src/build-scripts/common-args.hxml +++ b/src/build-scripts/common-args.hxml @@ -1,3 +1,4 @@ -lib hscript +-lib uuid -cp src -D analyzer-optimize \ No newline at end of file diff --git a/src/kiss/FieldForms.hx b/src/kiss/FieldForms.hx index 9887b191..f4af86c5 100644 --- a/src/kiss/FieldForms.hx +++ b/src/kiss/FieldForms.hx @@ -44,6 +44,7 @@ class FieldForms { }; } + // TODO make immutability the default static function varOrProperty(formName:String, position:Position, args:Array, convert:ExprConversion):Field { if (args.length != 2) { throw '$formName with $args at $position is not a valid field definition'; diff --git a/src/kiss/SpecialForms.hx b/src/kiss/SpecialForms.hx index 94c195b3..433982ae 100644 --- a/src/kiss/SpecialForms.hx +++ b/src/kiss/SpecialForms.hx @@ -4,6 +4,7 @@ import haxe.macro.Expr; import haxe.macro.Context; import kiss.Reader; import kiss.Types; +import uuid.Uuid; using kiss.Reader; using kiss.Helpers; @@ -41,9 +42,31 @@ class SpecialForms { ENew(Helpers.parseTypePath(classType), args.slice(1).map(convert)).withContextPos(); }; - // TODO special form for assignment + // TODO this isn't tested and doesn't give an arg length warning + map["set"] = (args:Array, convert:ExprConversion) -> { + EBinop(OpAssign, convert(args[0]), convert(args[1])).withContextPos(); + }; - // TODO special form for local var declaration + // TODO this isn't tested, immutable-default, or DRY with (let... ) or (defvar... ) and doesn't give an arg length warning + map["deflocal"] = (args:Array, convert:ExprConversion) -> { + EVars([ + { + name: switch (args[0].def) { + case Symbol(name) | TypedExp(_, {pos: _, def: Symbol(name)}): + name; + default: + throw 'first element of (deflocal... ) with $args should be a symbol or typed symbol'; + }, + type: switch (args[0].def) { + case TypedExp(type, _): + Helpers.parseComplexType(type); + default: null; + }, + isFinal: false, + expr: convert(args[1]) + } + ]).withContextPos(); + }; // TODO refactor out EVar generation and allow var bindings to destructure lists and key-value pairs map["let"] = (args:Array, convert:ExprConversion) -> { @@ -160,7 +183,10 @@ class SpecialForms { var thenExp = convert(args[1]); var elseExp = if (args.length > 2) convert(args[2]) else null; - EIf(condition, thenExp, elseExp).withContextPos(); + macro if ($condition) + $thenExp + else + $elseExp; }; return map;