mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-08 07:48:47 +00:00
Fixed bug in infix imports
This commit is contained in:
parent
455a529999
commit
a9946113c9
6 changed files with 41 additions and 23 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
infixr "++" at "+" (a, b) {return a+b}
|
infix "++" at "+" (a, b) {return a+b}
|
||||||
|
|
||||||
local x = read ();
|
local x = read ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
F,printf;
|
F,printf;
|
||||||
F,read;
|
F,read;
|
||||||
F,write;
|
F,write;
|
||||||
|
F,i__Infix_4343;
|
||||||
|
L,"++",T,"+";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,17 @@ static void printValue (void *p) {
|
||||||
printStringBuf ("\"%s\"", a->contents);
|
printStringBuf ("\"%s\"", a->contents);
|
||||||
break;
|
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:
|
case ARRAY_TAG:
|
||||||
printStringBuf ("[");
|
printStringBuf ("[");
|
||||||
for (i = 0; i < LEN(a->tag); i++) {
|
for (i = 0; i < LEN(a->tag); i++) {
|
||||||
|
|
@ -445,12 +456,25 @@ extern int Lraw (int x) {
|
||||||
extern void Lprintf (char *s, ...) {
|
extern void Lprintf (char *s, ...) {
|
||||||
va_list args = (va_list) BOX (NULL);
|
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);
|
va_start (args, s);
|
||||||
vprintf (s, args); // vprintf (char *, va_list) <-> printf (char *, ...)
|
vprintf (s, args); // vprintf (char *, va_list) <-> printf (char *, ...)
|
||||||
va_end (args);
|
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 *da = (data*) BOX (NULL);
|
||||||
data *db = (data*) BOX (NULL);
|
data *db = (data*) BOX (NULL);
|
||||||
data *d = (data*) BOX (NULL);
|
data *d = (data*) BOX (NULL);
|
||||||
|
|
|
||||||
|
|
@ -589,7 +589,7 @@ module Expr =
|
||||||
ignore atr (
|
ignore atr (
|
||||||
match s with
|
match s with
|
||||||
| ":" -> Sexp ("cons", [x; y])
|
| ":" -> Sexp ("cons", [x; y])
|
||||||
| "++" -> Call (Var "strcat", [x; y])
|
(*| "++" -> Call (Var "strcat", [x; y]) *)
|
||||||
| ":=" -> Assign (x, y)
|
| ":=" -> Assign (x, y)
|
||||||
| _ -> Binop (s, x, y)
|
| _ -> Binop (s, x, y)
|
||||||
)
|
)
|
||||||
|
|
@ -734,7 +734,7 @@ module Infix =
|
||||||
let exported =
|
let exported =
|
||||||
Array.map
|
Array.map
|
||||||
(fun (ass, (_, ops)) ->
|
(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
|
infix
|
||||||
in
|
in
|
||||||
|
|
@ -746,11 +746,11 @@ module Infix =
|
||||||
| (s, kind) :: tl ->
|
| (s, kind) :: tl ->
|
||||||
let loc' = match tl with [] -> `After s | _ -> `At s in
|
let loc' = match tl with [] -> `After s | _ -> `At s in
|
||||||
(fun again ->
|
(fun again ->
|
||||||
match kind with
|
match kind with
|
||||||
| Public -> again (loc', (ass, s, loc) :: acc)
|
| Public -> again (loc', (ass, s, loc) :: acc)
|
||||||
| _ -> again (loc', acc)
|
| _ -> again (loc', acc)
|
||||||
)
|
)
|
||||||
(match tl with [] -> fun acc -> acc | _ -> fun acc -> inner acc tl)
|
(match tl with [] -> fun acc -> acc | _ -> fun acc -> inner acc tl)
|
||||||
in
|
in
|
||||||
inner (loc, acc) list
|
inner (loc, acc) list
|
||||||
)
|
)
|
||||||
|
|
@ -770,7 +770,7 @@ module Infix =
|
||||||
`Lefta , ["!!"];
|
`Lefta , ["!!"];
|
||||||
`Lefta , ["&&"];
|
`Lefta , ["&&"];
|
||||||
`Nona , ["=="; "!="; "<="; "<"; ">="; ">"];
|
`Nona , ["=="; "!="; "<="; "<"; ">="; ">"];
|
||||||
`Lefta , ["++"; "+" ; "-"];
|
`Lefta , [(*"++";*) "+" ; "-"];
|
||||||
`Lefta , ["*" ; "/"; "%"];
|
`Lefta , ["*" ; "/"; "%"];
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
|
@ -838,7 +838,7 @@ module Definition =
|
||||||
ostap (
|
ostap (
|
||||||
arg : LIDENT;
|
arg : LIDENT;
|
||||||
position[pub][ass][coord][newp]:
|
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};
|
| f:(%"before" {Infix.before} | %"after" {Infix.after}) s:STRING {f coord (unquote s) newp ass pub};
|
||||||
head[infix]:
|
head[infix]:
|
||||||
m:(%"external" {`Extern} | %"public" e:(%"external")? {match e with None -> `Public | _ -> `PublicExtern})? %"fun" name:LIDENT {unopt_mod m, name, name, 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 *)
|
(* Top-level parser *)
|
||||||
ostap (
|
ostap (
|
||||||
imports[cmd]: l:$ is:(%"import" !(Util.list (ostap (LIDENT))) -";")* {
|
imports[cmd]: l:$ is:(%"import" !(Util.list (ostap (LIDENT))) -";")* {
|
||||||
let is = List.flatten is in
|
let is = "Std" :: List.flatten is in
|
||||||
let infix =
|
let infix =
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun infix import ->
|
(fun infix import ->
|
||||||
|
|
|
||||||
|
|
@ -360,7 +360,7 @@ object (self : 'self)
|
||||||
intfs
|
intfs
|
||||||
)
|
)
|
||||||
self
|
self
|
||||||
("Std" :: imports)
|
imports
|
||||||
in
|
in
|
||||||
env
|
env
|
||||||
|
|
||||||
|
|
|
||||||
11
src/X86.ml
11
src/X86.ml
|
|
@ -687,19 +687,10 @@ let build cmd prog =
|
||||||
List.filter (function `Import _ -> true | _ -> false) intfs) @
|
List.filter (function `Import _ -> true | _ -> false) intfs) @
|
||||||
imports)
|
imports)
|
||||||
in
|
in
|
||||||
iterate [] S.empty imports
|
iterate [] (S.add "Std" S.empty) imports
|
||||||
in
|
in
|
||||||
cmd#dump_file "s" (genasm cmd prog);
|
cmd#dump_file "s" (genasm cmd prog);
|
||||||
cmd#dump_file "i" (Interface.gen 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
|
let inc = try Sys.getenv "RC_RUNTIME" with _ -> "../runtime" in
|
||||||
match cmd#get_mode with
|
match cmd#get_mode with
|
||||||
| `Default ->
|
| `Default ->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue