Compare commits

...

9 Commits

  1. 42
      src/rustint/core.clj
  2. 72
      test/rustint/core_test.clj

@ -2097,10 +2097,33 @@
; [; (fn main ( ) { println! ( "{}" , TRES ) }) [use std :: io ; const TRES : i64 = 3] :sin-errores [[0] [[io [lib ()] 0] [TRES [const i64] 3]]] 0 [[CAL 0] HLT] []]
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn maxnil [a1 a2]
(cond
(and (nil? a1) (nil? a2)) nil
(nil? a1) a2
(nil? a2) a1
:else (max a1 a2)
)
)
(defn last_const_idx [seq]
(reduce maxnil (map-indexed (fn [idx itm] (if itm idx nil)) (map #(= 'const %1) seq)))
)
(defn cargar-const-en-tabla [amb]
(cond
(not= (get amb 4) :sin-errores) amb
:else nil
(not= (get amb 3) :sin-errores) amb
:else (let [
syp (get amb 2),
ctx (get amb 4),
idx_const (last_const_idx syp),
const_name (get syp (+ 1 idx_const)),
const_type (get syp (+ 3 idx_const)),
const_value (get syp (+ 5 idx_const)),
]
(assoc-in amb [4 1 (count (get ctx 1))] [const_name ['const const_type] const_value])
)
)
)
@ -2116,10 +2139,17 @@
; [{ (let x : i64 = 10 ; println! ( "{}" , x ) }) [fn main ( )] :sin-errores [[0 1] [[main [fn [() ()]] 2]]] 0 [[CAL 2] HLT] []]
; ^^^^^^^^^^^^ ^ ^^^^^^^^^^^^^^^^^^^^^^^
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; TODO
; (defn inicializar-contexto-local
;
;)
(defn inicializar-contexto-local [amb]
(cond
(not= (get amb 3) :sin-errores) amb
:else (let [
ctx (get amb 4),
]
(assoc-in amb [4 0 (count (get ctx 0))] (count (get ctx 1)))
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; RESTAURAR-CONTEXTO-ANTERIOR: Recibe un ambiente y, si su estado no es :sin-errores, lo devuelve intacto.

@ -609,7 +609,7 @@
)
)
(deftest test-cargar-const-en-tabla-01
(deftest test-cargar-const-en-tabla-01
(testing "Test 01 cargar-const-en-tabla"
(is (=
(cargar-const-en-tabla [
@ -645,7 +645,10 @@
(list 'fn 'main (symbol "(") (symbol ")") (symbol "{") 'println! (symbol "(") "{}" (symbol ",") 'TRES (symbol ")") (symbol "}"))
['use 'std (symbol "::") 'io (symbol ";") 'const 'TRES (symbol ":") 'i64 (symbol "=") 3]
:sin-errores
[[0] [['io ['lib '()] 0]]]
[[0] [
['io ['lib '()] 0]
]
]
0
[['CAL 0] 'HLT]
[]
@ -656,7 +659,11 @@
(list 'fn 'main (symbol "(") (symbol ")") (symbol "{") 'println! (symbol "(") "{}" (symbol ",") 'TRES (symbol ")") (symbol "}"))
['use 'std (symbol "::") 'io (symbol ";") 'const 'TRES (symbol ":") 'i64 (symbol "=") 3]
:sin-errores
[[0] [['io ['lib '()] 0] ['TRES ['const 'i64] 3]]]
[[0] [
['io ['lib '()] 0]
['TRES ['const 'i64] 3]
]
]
0
[['CAL 0] 'HLT]
[]
@ -665,3 +672,62 @@
)
)
)
(deftest test-inicializar-contexto-local-01
(testing "Test 01 inicializar-contexto-local"
(is (=
(inicializar-contexto-local
[
(symbol "{")
(list 'let 'x (symbol ":") 'i64 (symbol "=") 10 (symbol ";") 'println! (symbol "(") "{}" (symbol ",") 'x (symbol ")") (symbol "}"))
['fn 'main (symbol "(") (symbol ")")]
8
[[0] [['main ['fn [() ()]] 2]]]
0
[['CAL 2] 'HLT]
[]
]
)
[
(symbol "{")
(list 'let 'x (symbol ":") 'i64 (symbol "=") 10 (symbol ";") 'println! (symbol "(") "{}" (symbol ",") 'x (symbol ")") (symbol "}"))
['fn 'main (symbol "(") (symbol ")")]
8
[[0] [['main ['fn [() ()]] 2]]]
0
[['CAL 2] 'HLT]
[]
]
))
)
)
(deftest test-inicializar-contexto-local-02
(testing "Test 02 inicializar-contexto-local"
(is (=
(inicializar-contexto-local
[
(symbol "{")
(list 'let 'x (symbol ":") 'i64 (symbol "=") 10 (symbol ";") 'println! (symbol "(") "{}" (symbol ",") 'x (symbol ")") (symbol "}"))
['fn 'main (symbol "(") (symbol ")")]
:sin-errores
[[0] [['main ['fn [() ()]] 2]]]
0
[['CAL 2] 'HLT]
[]
]
)
[
(symbol "{")
(list 'let 'x (symbol ":") 'i64 (symbol "=") 10 (symbol ";") 'println! (symbol "(") "{}" (symbol ",") 'x (symbol ")") (symbol "}"))
['fn 'main (symbol "(") (symbol ")")]
:sin-errores
[[0 1] [['main ['fn [() ()]] 2]]]
0
[['CAL 2] 'HLT]
[]
]
)
)
)
)

Loading…
Cancel
Save