mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
Prohibit user functions with built-in names
This commit is contained in:
parent
907a9f4f93
commit
9fa02845cb
2 changed files with 18 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
infix ++ at + (a, b) { a+b}
|
infix +++ at + (a, b) { a+b}
|
||||||
|
|
||||||
var x = read ();
|
var x = read ();
|
||||||
|
|
||||||
write (infix ++ (2, 3))
|
write (infix +++ (2, 3))
|
||||||
21
src/X86.ml
21
src/X86.ml
|
|
@ -225,9 +225,6 @@ let show instr =
|
||||||
| Sar1 s -> Printf.sprintf "\tsarq\t%s" (opnd s)
|
| Sar1 s -> Printf.sprintf "\tsarq\t%s" (opnd s)
|
||||||
| Repmovsl -> Printf.sprintf "\trep movsq\t"
|
| Repmovsl -> Printf.sprintf "\trep movsq\t"
|
||||||
|
|
||||||
(* Opening stack machine to use instructions without fully qualified names *)
|
|
||||||
open SM
|
|
||||||
|
|
||||||
let in_memory = function M _ | S _ | I _ -> true | R _ | L _ -> false
|
let in_memory = function M _ | S _ | I _ -> true | R _ | L _ -> false
|
||||||
let big_numeric_literal = function L num -> num > 0xFFFFFFFF | _ -> false
|
let big_numeric_literal = function L num -> num > 0xFFFFFFFF | _ -> false
|
||||||
|
|
||||||
|
|
@ -423,8 +420,11 @@ let compile_call env ?fname nargs tail =
|
||||||
let allowed_function =
|
let allowed_function =
|
||||||
match fname with
|
match fname with
|
||||||
| Some fname ->
|
| Some fname ->
|
||||||
let is_vararg = Option.is_some @@ List.assoc_opt fname vararg_functions in
|
let is_vararg =
|
||||||
not (fname.[0] = 'B') && not is_vararg
|
Option.is_some @@ List.assoc_opt fname vararg_functions
|
||||||
|
in
|
||||||
|
let is_internal = fname.[0] = 'B' in
|
||||||
|
(not is_internal) && not is_vararg
|
||||||
| None -> true
|
| None -> true
|
||||||
in
|
in
|
||||||
let same_arguments_count = env#nargs = nargs in
|
let same_arguments_count = env#nargs = nargs in
|
||||||
|
|
@ -670,6 +670,17 @@ let compile cmd env imports code =
|
||||||
( env#set_stack l,
|
( env#set_stack l,
|
||||||
[ Sar1 x; (*!!!*) Binop ("cmp", L 0, x); CJmp (s, l) ] )
|
[ Sar1 x; (*!!!*) Binop ("cmp", L 0, x); CJmp (s, l) ] )
|
||||||
| BEGIN (f, nargs, nlocals, closure, args, scopes) ->
|
| BEGIN (f, nargs, nlocals, closure, args, scopes) ->
|
||||||
|
let _ =
|
||||||
|
let is_safepoint = List.mem f safepoint_functions in
|
||||||
|
let is_vararg =
|
||||||
|
Option.is_some @@ List.assoc_opt f vararg_functions
|
||||||
|
in
|
||||||
|
if is_safepoint || is_vararg then
|
||||||
|
raise
|
||||||
|
(Failure
|
||||||
|
(Printf.sprintf
|
||||||
|
"Function name %s is reserved for built-in" f))
|
||||||
|
in
|
||||||
let rec stabs_scope scope =
|
let rec stabs_scope scope =
|
||||||
let names =
|
let names =
|
||||||
List.map
|
List.map
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue