Compare commits

...

8 Commits

  1. 49
      src/rustint/core.clj
  2. 81
      test/rustint/core_test.clj

@ -1900,10 +1900,35 @@
; ;
; nil ; nil
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TODO (defn flistar [ilevel t nxt]
;(defn listar (cond
; (string? t) (format "\"%s\" " t)
;) (= t (symbol "{")) (clojure.string/join
(cons "\n{\n" (repeat (* ilevel 2) " "))
)
(= t (symbol "}")) "\n}"
(and (not= nxt (symbol "{")) (not= nxt (symbol "}"))) (format "%s " t)
:else (format "%s" t)
)
)
(defn listar [l]
(let [contadores (hash-map (symbol "{") 1, (symbol "}") -1),
ident_levels (reductions + (map #(get contadores %1 0) l)),
]
(dorun
(
map
print
(map
#(apply flistar (cons %1 %2))
ident_levels
(partition 2 1 (concat l '(nil)))
)
)
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AGREGAR-PTOCOMA: Recibe una lista con los tokens de un programa en Rust y la devuelve con un token ; insertado a continuacion de ciertas } (llaves de cierre, pero no a continuacion de todas ellas). ; AGREGAR-PTOCOMA: Recibe una lista con los tokens de un programa en Rust y la devuelve con un token ; insertado a continuacion de ciertas } (llaves de cierre, pero no a continuacion de todas ellas).
@ -2046,10 +2071,18 @@
; user=> (ya-declarado-localmente? 'Write [[0 2] [['io ['lib '()] 0] ['Write ['lib '()] 0] ['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]]]) ; user=> (ya-declarado-localmente? 'Write [[0 2] [['io ['lib '()] 0] ['Write ['lib '()] 0] ['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]]])
; false ; false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TODO (defn in?
;(defn ya-declarado-localmente? "true if coll contains elm"
; [coll elm]
;) (boolean (some #(= elm %) coll))
)
(defn ya-declarado-localmente? [ident ctx]
(let [inicio_scope_local (last (get ctx 0)),
scope_local (subvec (get ctx 1) inicio_scope_local),
identificadores_scope_local (map first scope_local)
] (in? identificadores_scope_local ident))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CARGAR-CONST-EN-TABLA: Recibe un ambiente ; CARGAR-CONST-EN-TABLA: Recibe un ambiente

@ -446,3 +446,84 @@
) )
) )
) )
(deftest test-listar-01
(testing "Test 01 listar"
(let [
printed (with-out-str (listar (list 'fn 'main (symbol "(") (symbol ")") (symbol "{") 'println! (symbol "(") "Hola, mundo!" (symbol ")") (symbol "}"))))
]
(is (=
printed
"fn main ( )\n{\n println! ( \"Hola, mundo!\" )\n}"
)
)
)
)
)
(deftest test-ya-declarado-localmente-01
(testing "Test 01 ya-declarado-localmente?"
(is (= (ya-declarado-localmente?
'Write
[
[0]
[
['io ['lib '()] 0]
['Write ['lib '()] 0]
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
]
]
) true))
)
)
(deftest test-ya-declarado-localmente-02
(testing "Test 02 ya-declarado-localmente?"
(is (= (ya-declarado-localmente?
'Read
[
[0]
[
['io ['lib '()] 0]
['Write ['lib '()] 0]
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
]
]
)
false))
)
)
(deftest test-ya-declarado-localmente-03
(testing "Test 03 ya-declarado-localmente?"
(is (= (ya-declarado-localmente?
'Write
[
[0 1]
[
['io ['lib '()] 0]
['Write ['lib '()] 0]
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
]
]
)
true))
)
)
(deftest test-ya-declarado-localmente-04
(testing "Test 04 ya-declarado-localmente?"
(is (= (ya-declarado-localmente?
'Write
[
[0 2]
[
['io ['lib '()] 0]
['Write ['lib '()] 0]
['entero_a_hexa ['fn [(list ['n (symbol ":") 'i64]) 'String]] 2]
]
]
)
false))
)
)

Loading…
Cancel
Save