From: Mike Lowis Date: Fri, 10 Nov 2023 17:59:08 +0000 (-0500) Subject: added front end X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=12b11c66d89b180d1f8717c5d349905cd0cfa839;p=proto%2Faas.git added front end --- diff --git a/cerise b/cerise new file mode 100755 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 diff --git a/cerise.m b/cerise.m index 37db56c..81920d1 100644 --- a/cerise.m +++ b/cerise.m @@ -1,8 +1,4 @@ -#export( -# main -#) - main() { - return 0 + return 42 } diff --git a/cerise.rb b/cerise.rb index b43ccba..35bb776 100755 --- 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