]> git.mdlowis.com Git - proto/aas.git/commitdiff
added front end
authorMike Lowis <mike.lowis@gentex.com>
Fri, 10 Nov 2023 17:59:08 +0000 (12:59 -0500)
committerMike Lowis <mike.lowis@gentex.com>
Fri, 10 Nov 2023 17:59:08 +0000 (12:59 -0500)
cerise [new file with mode: 0755]
cerise.m
cerise.rb

diff --git a/cerise b/cerise
new file mode 100755 (executable)
index 0000000..064aff2
--- /dev/null
+++ b/cerise
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+output="a.out"
+objects=""
+
+# Parse command line options
+while :; do
+    case $1 in
+        -o|--output)
+            if [ -n "$2" ]; then
+                output=$2
+                shift
+            else
+                printf 'ERROR: "--output" requires a non-empty option argument.\n' >&2
+                exit 1
+            fi
+            ;;
+        --output=?*)
+            output=${1#*=}
+            ;;
+        --output=)
+            printf 'ERROR: "--file" requires a non-empty option argument.\n' >&2
+            exit 1
+            ;;
+        *)
+            break
+    esac
+    shift
+done
+
+# Now assemble all the files
+PATH="$PWD:$PATH"
+export PATH
+for f in "$@"; do
+  cerise.rb "$f" > "$f.s"
+  aas.rb "$f.s" | as - -o "$f.o"
+  rm -f "$f.s"
+  objects="$objects $f.o"
+done
+
+# And link them altogether
+ld --gc-sections -o "$output" $objects
\ No newline at end of file
index 37db56cf23bd92b44e7550394793f36553c18473..81920d1b28b547791c960915487a82e9deab1c81 100644 (file)
--- a/cerise.m
+++ b/cerise.m
@@ -1,8 +1,4 @@
-#export(
-#    main
-#)
-
 main()
 {
-    return 0
+    return 42
 }
index b43ccbab161d1bb54d6bc6d872a3efa8feb7b3c4..35bb776d867e3b99d264ce294485d5d660c5be68 100755 (executable)
--- a/cerise.rb
+++ b/cerise.rb
@@ -895,15 +895,23 @@ module Codegen
   end
 
   def self.emit_return(v)
+    emit(v.value)
+    puts "    retwv"
   end
 
   def self.emit_const(v)
+    if v.value.is_a? Integer
+      puts "    int #{v.value}"
+    end
   end
 end
 
 $parser = Parser.new("cerise.m")
 $parser.defs.each do |name, val|
   puts "func #{name.to_sym.inspect} do"
+  val.value.body.each do |stmnt|
+    Codegen.emit(stmnt)
+  end
   puts "end"
-  puts val
+#  puts val
 end