Fixed bug in infix imports

This commit is contained in:
Dmitry Boulytchev 2019-12-18 18:44:01 +03:00
parent 455a529999
commit a9946113c9
6 changed files with 41 additions and 23 deletions

View file

@ -1,4 +1,4 @@
infixr "++" at "+" (a, b) {return a+b}
infix "++" at "+" (a, b) {return a+b}
local x = read ();

View file

@ -1,3 +1,6 @@
F,printf;
F,read;
F,write;
F,i__Infix_4343;
L,"++",T,"+";

View file

@ -164,6 +164,17 @@ static void printValue (void *p) {
printStringBuf ("\"%s\"", a->contents);
break;
case CLOSURE_TAG:
printStringBuf ("<closure ");
for (i = 0; i < LEN(a->tag); i++) {
if (i) printValue ((void*)((int*) a->contents)[i]);
else printStringBuf ("%x", (void*)((int*) a->contents)[i]);
if (i != LEN(a->tag) - 1) printStringBuf (", ");
}
printStringBuf (">");
break;
case ARRAY_TAG:
printStringBuf ("[");
for (i = 0; i < LEN(a->tag); i++) {
@ -445,12 +456,25 @@ extern int Lraw (int x) {
extern void Lprintf (char *s, ...) {
va_list args = (va_list) BOX (NULL);
//void *p = &s;
//char *c = s;
//printf ("%d\n", ((int*)p)[2]);
/*
while (*c) {
if (*c == '%') {
p++;
printf ("arg: %d\n", *(int*)p);
}
c++;
}
*/
va_start (args, s);
vprintf (s, args); // vprintf (char *, va_list) <-> printf (char *, ...)
va_end (args);
}
extern void* Lstrcat (void *a, void *b) {
extern void* /*Lstrcat*/ i__Infix_4343 (void *a, void *b) {
data *da = (data*) BOX (NULL);
data *db = (data*) BOX (NULL);
data *d = (data*) BOX (NULL);

View file

@ -589,7 +589,7 @@ module Expr =
ignore atr (
match s with
| ":" -> Sexp ("cons", [x; y])
| "++" -> Call (Var "strcat", [x; y])
(*| "++" -> Call (Var "strcat", [x; y]) *)
| ":=" -> Assign (x, y)
| _ -> Binop (s, x, y)
)
@ -734,7 +734,7 @@ module Infix =
let exported =
Array.map
(fun (ass, (_, ops)) ->
(ass, List.map (fun (s, kind, _) -> s, kind) @@ List.filter (function (_, Public, _) | (_, Predefined, _) -> true | _ -> false) ops)
(ass, List.rev @@ List.map (fun (s, kind, _) -> s, kind) @@ List.filter (function (_, Public, _) | (_, Predefined, _) -> true | _ -> false) ops)
)
infix
in
@ -770,7 +770,7 @@ module Infix =
`Lefta , ["!!"];
`Lefta , ["&&"];
`Nona , ["=="; "!="; "<="; "<"; ">="; ">"];
`Lefta , ["++"; "+" ; "-"];
`Lefta , [(*"++";*) "+" ; "-"];
`Lefta , ["*" ; "/"; "%"];
|]
@ -838,7 +838,7 @@ module Definition =
ostap (
arg : LIDENT;
position[pub][ass][coord][newp]:
%"at" s:STRING {Infix.at coord (unquote s) newp pub}
%"at" s:STRING {match ass with `Nona -> Infix.at coord (unquote s) newp pub | _ -> raise (Semantic_error (Printf.sprintf "associativity for infxi '%s' can not be specified (it is inherited from that for '%s')" newp s))}
| f:(%"before" {Infix.before} | %"after" {Infix.after}) s:STRING {f coord (unquote s) newp ass pub};
head[infix]:
m:(%"external" {`Extern} | %"public" e:(%"external")? {match e with None -> `Public | _ -> `PublicExtern})? %"fun" name:LIDENT {unopt_mod m, name, name, infix}
@ -963,7 +963,7 @@ let eval (_, expr) i =
(* Top-level parser *)
ostap (
imports[cmd]: l:$ is:(%"import" !(Util.list (ostap (LIDENT))) -";")* {
let is = List.flatten is in
let is = "Std" :: List.flatten is in
let infix =
List.fold_left
(fun infix import ->

View file

@ -360,7 +360,7 @@ object (self : 'self)
intfs
)
self
("Std" :: imports)
imports
in
env

View file

@ -687,19 +687,10 @@ let build cmd prog =
List.filter (function `Import _ -> true | _ -> false) intfs) @
imports)
in
iterate [] S.empty imports
iterate [] (S.add "Std" S.empty) imports
in
cmd#dump_file "s" (genasm cmd prog);
cmd#dump_file "i" (Interface.gen prog);
(*
let name = Filename.chop_suffix cmd#get_infile ".expr" in
let outf = open_out (Printf.sprintf "%s.s" name) in
Printf.fprintf outf "%s" (genasm cmd prog);
close_out outf;
let outf = open_out (Printf.sprintf "%s.i" name) in
Printf.fprintf outf "%s" (Interface.gen prog);
close_out outf;
*)
let inc = try Sys.getenv "RC_RUNTIME" with _ -> "../runtime" in
match cmd#get_mode with
| `Default ->