Skip to content

Commit

Permalink
chore: Add more comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
vantreeseba committed Jun 7, 2024
1 parent b7212f5 commit 206c1c7
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 113 deletions.
8 changes: 0 additions & 8 deletions build.hxml

This file was deleted.

86 changes: 0 additions & 86 deletions dump/decoding_error.txt

This file was deleted.

4 changes: 3 additions & 1 deletion haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "dropecho.macros",
"description": "A set of utlity macros for haxe.",
"classPath": "src/",
"dependencies": {},
"dependencies": {
"tink_macro": ""
},
"url": "https://github.com/dropecho/macros.hx",
"contributors": [
"vantreeseba"
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"repository": "github:dropecho/macros.hx",
"license": "MIT",
"scripts": {
"build": "npm run clean && haxe build.hxml",
"test": "haxelib run munit t",
"clean": "rm -rf dist && rm -rf artifacts"
"test": "haxe test.hxml"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.2",
Expand Down
20 changes: 18 additions & 2 deletions src/dropecho/macros/Constructor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@ using Lambda;
typedef TypeMacros = dropecho.macros.TypeBuildingMacros;

class Constructor {
macro static public function fromParams(pub:Bool = false):Array<Field> {
/**
Builds the body of a constructor based on the arguments.
Also creates fields on the class from them.
i.e. function new(a:Int, b:Int);
this creates fields a,b on class, and assigns the passed value in body.
@param [pub] Should the created fields be public.
@returns The created fields.
*/
macro static public function fromArgs(pub:Bool = false):Array<Field> {
var fields = Context.getBuildFields();
var constructor = fields.find(x -> x.name == "new");

Expand All @@ -34,6 +44,12 @@ class Constructor {
return fields;
}

/**
* Auto creates a constructor based on the fields of a class.
*
* @param [allOpt] Should all the params be optional?
* @returns The fields (including the generated constructor) in an array.
*/
macro static public function fromFields(allOpt:Bool = false):Array<Field> {
var fields = Context.getBuildFields();
var constructorArgs = [];
Expand All @@ -47,7 +63,7 @@ class Constructor {
name: f.name,
type: t,
opt: allOpt,
value: TypeMacros.isConstant(val) ? $v{val} : null
value: TypeMacros.isConstant(val) ? $v{val} : null
});
f.kind = FieldType.FVar(t, null);
default:
Expand Down
10 changes: 10 additions & 0 deletions src/dropecho/macros/TypeBuildingMacros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import haxe.macro.ExprTools;
using Lambda;

class TypeBuildingMacros {
/**
Checks if an expression if null or empty.
If expression is function, checks if the body is empty.
@param expr - The expression to check.
@returns [TODO:description]
*/
static public function isEmpty(expr:Expr) {
if (expr == null) {
return true;
Expand All @@ -17,6 +24,9 @@ class TypeBuildingMacros {
}
}

/**
* Checks if an expression is a constant expr.
*/
static public function isConstant(expr:Expr) {
if (isEmpty(expr)) {
return false;
Expand Down
36 changes: 23 additions & 13 deletions test.hxml
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
-cp src
-cp test
--class-path src
--class-path test

#test libs
-lib tink_macro
-lib autotest
-lib buddy
# -lib autotest
--library tink_macro
--library buddy
--library instrument
--define buddy-colors

--macro instrument.Instrumentation.coverage(['dropecho'], ['src'], [])
--define coverage-console-summary-reporter
--define coverage-lcov-reporter

-x TestMain

# --each

# --next
# -lib hxnodejs
# -D js-es=6
# -js artifacts/test/js_test.js

--each

--next
-lib hxnodejs
-D js-es=6
-js artifacts/test/js_test.js
# --next
# -neko artifacts/test/test.n
# --next
# -cs artifacts/test/cs_test

--next
--cmd echo "JS TESTS"
--cmd node ./artifacts/test/js_test.js
# --next
# --cmd echo "JS TESTS"
# --cmd node ./artifacts/test/js_test.js

# --cmd echo "NEKO TESTS"
# --cmd neko ./artifacts/test/test.n
Expand Down
6 changes: 6 additions & 0 deletions test/TestMain.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import buddy.*;

using buddy.Should;

// Implement "Buddy" and define an array of classes within the brackets:
class TestMain implements Buddy<[dropecho.macros.ConstructorTests]> {}

0 comments on commit 206c1c7

Please sign in to comment.