]> rethought.computer Git - sorel-lang.git/commitdiff
add externs and putstack for testing keep/2c640a274f16bd9c219ab54b6658a9c481da651a
authorBryan English <bryan@rethought.computer>
Mon, 9 Feb 2026 14:32:20 +0000 (09:32 -0500)
committerBryan English <bryan@rethought.computer>
Tue, 10 Feb 2026 04:08:54 +0000 (04:08 +0000)
rel-lang/sorelc/src/ir.rs
rel-lang/sorelc/src/parser.rs
rel-lang/tests/putstack.c [new file with mode: 0644]
rel-lang/tests/test.sh

index 324ca6dd210efa7132ec3ea85d937ad8ec4e1c62..61e61156c8f6c5bd3e6b07031319bec79a5a26de 100644 (file)
@@ -20,6 +20,7 @@ struct IRModule {
     text: Vec<IR>,
     imports: Vec<Rc<IRModule>>,
     exports: Vec<String>,
+    externs: Vec<String>,
     // TODO these next two should form an enum, not two options
     source_file: Option<PathBuf>,
     std_specifier: Option<String>,
@@ -28,6 +29,9 @@ struct IRModule {
 
 impl IRModule {
     fn get_label_for_call(&self, name: &String) -> String {
+        if self.externs.contains(name) {
+            return name.clone();
+        }
         let mut found: Option<usize> = None;
         for imported in &self.imports {
             if imported.exports.contains(name) {
@@ -96,7 +100,10 @@ impl ImportTree {
             }
 
             let contents = &std::fs::read_to_string(&path)?;
-            let module = self.generate_internal(Some(path), None, &Module::parse(tokenize(&contents)?, is_entrypoint)?);
+            let tokens = tokenize(&contents)?;
+            let parsed = &Module::parse(tokens, is_entrypoint)?;
+
+            let module = self.generate_internal(Some(path), None, parsed);
             let module = Rc::new(module);
             self.all_modules.insert(path_key, module.clone());
             if is_entrypoint {
@@ -147,6 +154,7 @@ impl ImportTree {
             s.to_string()
         }).collect();
 
+        let externs = module.externs.iter().map(|s| s.to_string()).collect();
 
         text.push(module.words.iter().map(|def| {
             let mut body = def.instructions.iter().map(|inst| {
@@ -225,6 +233,7 @@ impl ImportTree {
             data,
             imports,
             exports,
+            externs,
             source_file: path,
             std_specifier, 
             number,
index 32141395c6805919946fe30ab79b31f5d7fdf385..94b53e44f699bc9139f2c55d1721b726b92fc331 100644 (file)
@@ -12,6 +12,7 @@ pub struct Module<'a> {
     pub words: Vec<WordDefinition<'a>>,
     pub imports: Vec<&'a str>,
     pub exports: Vec<&'a str>,
+    pub externs: Vec<&'a str>,
 }
 
 impl<'a> Module<'a> {
@@ -20,10 +21,12 @@ impl<'a> Module<'a> {
         let mut main = vec![];
         let mut exports = vec![];
         let mut imports = vec![];
+        let mut externs = vec![];
         let mut current_word: Option<WordDefinition> = None;
         let mut about_to_start_word_def = false;
         let mut last_was_import = false;
         let mut last_was_export = false;
+        let mut last_was_extern = false;
 
         for token in input {
             if about_to_start_word_def {
@@ -64,10 +67,15 @@ impl<'a> Module<'a> {
                             last_was_import = true;
                         } else if word == "export" {
                             last_was_export = true;
+                        } else if word == "extern" {
+                            last_was_extern = true;
                         } else {
                             if last_was_export {
                                 exports.push(word);
                                 last_was_export = false;
+                            } else if last_was_extern {
+                                externs.push(word);
+                                last_was_extern = false;
                             } else {
                                 main.push(token.clone());
                             }
@@ -99,7 +107,7 @@ impl<'a> Module<'a> {
             });
         }
         
-        Ok(Module { words: result, imports, exports })
+        Ok(Module { words: result, imports, exports, externs })
     }
 
     #[cfg(test)]
diff --git a/rel-lang/tests/putstack.c b/rel-lang/tests/putstack.c
new file mode 100644 (file)
index 0000000..a5200c4
--- /dev/null
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+extern unsigned long data_stack_end;
+register unsigned long * stack_pointer asm("s2");
+
+void putstack() {
+  unsigned long * stack_index = &data_stack_end;
+  printf("stack: ");
+  while (stack_index != stack_pointer) {
+         printf("%ld ", *stack_index);
+    stack_index -= 1;
+  }
+       printf("%ld\n", *stack_pointer);
+}
+
+
index e6f7b220a9508dabd4a6d8a67986e766bd93ea19..279addce6ec9d9cf07aebaa084bb74fd4804b4c8 100644 (file)
@@ -2,8 +2,10 @@ UNAME=$(uname -m)
 CMD_PREFIX=$([ "$UNAME" = "riscv64" ] && echo "" || echo "riscv64-unknown-linux-gnu-")
 AS="${CMD_PREFIX}as"
 LD="${CMD_PREFIX}ld"
+CC="${CMD_PREFIX}cc"
 
 ../target/debug/sorelc test1.sorel
 $AS -g -o test1.o test1.asm
-$LD -o test1.out test1.o
+$CC -O1 -no-pie -o test1.out test1.o putstack.c -nostartfiles 
+# $LD -o test1.out test1.o
 ./test1.out