Skip to content

Commit 788f825

Browse files
Keryan-devpoechsel
authored andcommitted
Special constructor for %sys_argv primitive (#166)
1 parent 0380ead commit 788f825

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ocaml/lambda/translprim.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type loc_kind =
8080
type prim =
8181
| Primitive of Lambda.primitive * int
8282
| External of Primitive.description
83+
| Sys_argv
8384
| Comparison of comparison * comparison_kind
8485
| Raise of Lambda.raise_kind
8586
| Raise_with_backtrace
@@ -349,7 +350,7 @@ let primitives_table =
349350
"%bswap_native", Primitive ((Pbbswap(Pnativeint)), 1);
350351
"%int_as_pointer", Primitive (Pint_as_pointer, 1);
351352
"%opaque", Primitive (Popaque, 1);
352-
"%sys_argv", External prim_sys_argv;
353+
"%sys_argv", Sys_argv;
353354
"%send", Send;
354355
"%sendself", Send_self;
355356
"%sendcache", Send_cache;
@@ -645,8 +646,8 @@ let lambda_of_prim prim_name prim loc args arg_exps =
645646
match prim, args with
646647
| Primitive (prim, arity), args when arity = List.length args ->
647648
Lprim(prim, args, loc)
648-
| External prim, args when prim = prim_sys_argv ->
649-
Lprim(Pccall prim, Lconst (const_int 0) :: args, loc)
649+
| Sys_argv, [] ->
650+
Lprim(Pccall prim_sys_argv, [Lconst (const_int 0)], loc)
650651
| External prim, args ->
651652
Lprim(Pccall prim, args, loc)
652653
| Comparison(comp, knd), ([_;_] as args) ->
@@ -694,7 +695,7 @@ let lambda_of_prim prim_name prim loc args arg_exps =
694695
| Send_cache, [obj; meth; cache; pos] ->
695696
Lsend(Cached, meth, obj, [cache; pos], loc)
696697
| (Raise _ | Raise_with_backtrace
697-
| Lazy_force | Loc _ | Primitive _ | Comparison _
698+
| Lazy_force | Loc _ | Primitive _ | Sys_argv | Comparison _
698699
| Send | Send_self | Send_cache), _ ->
699700
raise(Error(to_location loc, Wrong_arity_builtin_primitive prim_name))
700701

@@ -704,6 +705,7 @@ let check_primitive_arity loc p =
704705
match prim with
705706
| Primitive (_,arity) -> arity = p.prim_arity
706707
| External _ -> true
708+
| Sys_argv -> p.prim_arity = 0
707709
| Comparison _ -> p.prim_arity = 2
708710
| Raise _ -> p.prim_arity = 1
709711
| Raise_with_backtrace -> p.prim_arity = 2
@@ -778,7 +780,7 @@ let lambda_primitive_needs_event_after = function
778780
(* Determine if a primitive should be surrounded by an "after" debug event *)
779781
let primitive_needs_event_after = function
780782
| Primitive (prim,_) -> lambda_primitive_needs_event_after prim
781-
| External _ -> true
783+
| External _ | Sys_argv -> true
782784
| Comparison(comp, knd) ->
783785
lambda_primitive_needs_event_after (comparison_primitive comp knd)
784786
| Lazy_force | Send | Send_self | Send_cache -> true

0 commit comments

Comments
 (0)