quick implementations of deflocal, set

This commit is contained in:
2020-11-25 07:01:29 -07:00
parent de85eee100
commit bfef1859d7
4 changed files with 33 additions and 4 deletions

View File

@@ -10,6 +10,7 @@
"classPath": "src/",
"main": "kiss.Main",
"dependencies": {
"hscript": ""
"hscript": "",
"utest": ""
}
}

View File

@@ -1,3 +1,4 @@
-lib hscript
-lib uuid
-cp src
-D analyzer-optimize

View File

@@ -44,6 +44,7 @@ class FieldForms {
};
}
// TODO make immutability the default
static function varOrProperty(formName:String, position:Position, args:Array<ReaderExp>, convert:ExprConversion):Field {
if (args.length != 2) {
throw '$formName with $args at $position is not a valid field definition';

View File

@@ -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<ReaderExp>, 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<ReaderExp>, 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<ReaderExp>, 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;