Skip to content

Commit

Permalink
add Compiler.setHxbWriterConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jan 25, 2024
1 parent 5fd1549 commit ac56d11
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/macro/eval/evalDataApi.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
open EvalValue
open EvalContext
open EvalDecode

type data = value

let read_optional v f = match v with
| VNull ->
()
| _ ->
f v

let read_object v =
List.map (fun (i,v) ->
EvalHash.rev_hash i,v
) (object_fields (decode_object v))

let read_array v =
EvalArray.to_list (decode_varray v)

let read_string v =
decode_string v

let read_int v =
decode_int v

let read_bool v =
decode_bool v

let data_to_string v =
(EvalPrinting.s_value 0 v).sstring
5 changes: 5 additions & 0 deletions src/macro/macroApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type 'value compiler_api = {
with_imports : 'a . import list -> placed_name list list -> (unit -> 'a) -> 'a;
with_options : 'a . compiler_options -> (unit -> 'a) -> 'a;
exc_string : 'a . string -> 'a;
set_hxb_writer_config : 'value -> unit;
}


Expand Down Expand Up @@ -2405,5 +2406,9 @@ let macro_api ccom get_api =
vbool false
end
);
"set_hxb_writer_config", vfun1 (fun v ->
(get_api()).set_hxb_writer_config v;
vnull
)
]
end
11 changes: 11 additions & 0 deletions src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ module Interp = struct
include BuiltApi
end


module HxbWriterConfigReaderJson = HxbWriterConfig.WriterConfigReader(EvalDataApi)

let macro_interp_cache = ref None

let safe_decode com v expected t p f =
Expand Down Expand Up @@ -305,6 +308,14 @@ let make_macro_com_api com mcom p =
com.warning ~depth w [] msg p
);
exc_string = Interp.exc_string;
set_hxb_writer_config = (fun v ->
match com.hxb_writer_config with
| Some config ->
print_endline "READING CONFIG!!!";
HxbWriterConfigReaderJson.read_writer_config config (platform_name com.platform) v
| None ->
()
)
}

let make_macro_api ctx mctx p =
Expand Down
12 changes: 6 additions & 6 deletions std/haxe/hxb/WriterConfig.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ typedef WriterTargetConfig = {
/**
If `false`, this target is ignored by the writer.
**/
var generate:Null<Bool>;
var ?generate:Null<Bool>;

/**
Dot paths of modules or packages to be exluded from the archive.
**/
var exclude:Null<Array<String>>;
var ?exclude:Null<Array<String>>;

/**
Dot paths of modules or packages to be included in the archive. This takes priority
over exclude. By default, all modules that aren't explicitly excluded are
included.
**/
var include:Null<Array<String>>;
var ?include:Null<Array<String>>;

/**
The hxb version to target. By default, the version of the Haxe compiler itself
is targeted. See https://github.com/HaxeFoundation/haxe/issues/11505
**/
var hxbVersion:Null<Int>;
var ?hxbVersion:Null<Int>;
}

typedef WriterConfig = {
Expand All @@ -36,11 +36,11 @@ typedef WriterConfig = {
The configuration for the current target context. If it is `null`, all data
for the target context is generated.
**/
var targetConfig:Null<WriterTargetConfig>;
var ?targetConfig:Null<WriterTargetConfig>;

/**
The configuration for the macro context. If it is `null`, all data for the
macro context is generated.
**/
var macroConfig:Null<WriterTargetConfig>;
var ?macroConfig:Null<WriterTargetConfig>;
}
7 changes: 7 additions & 0 deletions std/haxe/macro/Compiler.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package haxe.macro;

import haxe.display.Display;
import haxe.macro.Expr;
import haxe.hxb.WriterConfig;

/**
All these methods can be called for compiler configuration macros.
Expand Down Expand Up @@ -576,6 +577,12 @@ class Compiler {
}
}
#end

static public function setHxbWriterConfiguration(config:WriterConfig) {
#if macro
load("set_hxb_writer_config", 1)(config);
#end
}
}

enum abstract IncludePosition(String) from String to String {
Expand Down

0 comments on commit ac56d11

Please sign in to comment.