908d29ff58f3 — Leonard Ritter 4 days ago
* removed unused module from noir space
1 files changed, 0 insertions(+), 272 deletions(-)

R lib/scopes/compiler/noir/parser.sc => 
R lib/scopes/compiler/noir/parser.sc =>  +0 -272
@@ 1,272 0,0 @@ 
-using import struct print itertools switcher
-using import ...Parser
-using import ...Lexer ...MappedFile
-    compiler.arcmem
-    compiler.arcmem.String
-    compiler.arcmem.Array
-    compiler.arcmem.Map
-using import .IRABI
-
-using Module.Id
-
-from Parser let Kind
-
-from Module let CellDataType
-
-inline String->celldata (str)
-    bitcast (storagecast str) CellDataType
-
-#
-    a list consists of untyped u64 values and pointers to arbitrary memory
-
-    the first element of a list always needs to be a pointer to a host-created
-    uri string; the same pointer in fact. you need that pointer to make
-    objects of this kind, and all pointers starting with this pointer are
-    treated as lists; otherwise they are strings/userdata.
-
-    OR
-
-    Open Variant
-
-    a variant object is a pair of schema and value
-
-    to dispatch built-in schemas, we use offset pointers into an array of
-    schemas; the pointer offset is constant in every program execution and can
-    be used for switch cases. schemas themselves also use a variant header.
-
-    anchored<T>: trace, value of T
-    list: pointer to array of variants
-    string: pointer to array of anything
-    symbol: xxhash
-    s<x>/u<x>: signed/unsigned integer of x bits, where x = 8,16,32,64
-    s128/u128: pointer to signed/unsigned integer of 128 bits
-    f<x>: float of x bits, where x = 32, 64
-
-enum IdKind : u8
-    list
-    string
-    symbol
-    i8
-    i16
-    i32
-    i64
-    i128
-    u8
-    u16
-    u32
-    u64
-    u128
-    char
-    usize
-    f32
-    f64
-
-struct UVMParser < Parser
-    module : Module
-    filepath : Cell
-    symbols : Array Cell
-    stack = (Array (tuple Location (Array Value)))
-        typeinit;
-    cursor : Location
-    str : String
-    str_cursor : Location
-    str_kind : Kind
-
-    inline offset-location (self loc)
-        local loc := loc
-        loc.line += self.cursor.line - 1
-        loc.column += self.cursor.column - 1
-        loc
-
-    inline __typecall (cls filepath cursor)
-        local self := super-type.__typecall cls
-            cursor = cursor
-        self.filepath = self.module.cell
-            String->celldata (String filepath)
-        deref self
-
-    inline builtin (self sym)
-        self.symbols @ (getattr builtin-symbols sym)
-
-    inline finalize (self)
-        'finalize self.pool
-        super-type.finalize self
-        loc item := 'explode (deref ('pop self.stack))
-        item
-
-    inline error (self start end ...)
-        start := 'offset-location self start
-        print2
-            /.. self.filepath ":" (/dec start.line) ":" (/dec start.column) ":"
-            ...
-        abort;
-
-    fn gen-anchor (self begin end)
-        self.module.anchor
-            file = self.filepath
-            begin = begin.offset
-            end = end.offset
-            line = begin.line
-            column = begin.column
-
-    inline append-any (self begin end item)
-        begin := 'offset-location self begin
-        end := 'offset-location self end
-        self.module.debuginfo
-            value = item
-            anchor = 'gen-anchor self begin end
-        dest := ('last self.stack) @ 1
-        'append dest item
-
-    inline begin-string (self cursor kind capacity)
-        self.str_cursor = cursor
-        self.str_kind = kind
-        self.str = ""
-    inline string-data (self ptr size)
-        'append-from-arrayptr self.str ptr size
-    inline string-char (self ch)
-        'append self.str ch
-    fn end-string (self end)
-        str := popswap self.str (String)
-        inline prefixed-const (prefix)
-            prefix := "type:" .. (prefix as zarray)
-            static-assert (constant? prefix)
-            Cell
-                Symbol
-                    'copystr self.pool
-                        'data prefix
-                Const data...
-        'begin-list self self.str_cursor
-        switcher sw
-            case 'String
-                'append-any self
-                    self.str_cursor
-                    self.str_cursor
-                    'builtin self 'string
-                'append-any self
-                    self.str_cursor
-                    end
-                    self.module.cell
-                        String->celldata str
-                'end-list self end false
-            case 'Symbol
-                'begin-list self self.str_cursor
-                'append-any self
-                    self.str_cursor
-                    self.str_cursor
-                    'builtin self 'symbol
-                'append-any self
-                    self.str_cursor
-                    end
-                    self.module.cell
-                        String->celldata str
-                'end-list self end false
-            default
-                report "todo:" self.str_kind
-                assert false
-        va-map
-            inline (tag)
-                switcher+ sw
-                    case tag
-                        prefixed-const tag
-            'i8
-            'i16
-            'i32
-            'i64
-            'i128
-            'u8
-            'u16
-            'u32
-            'u64
-            'u128
-            'char
-            'usize
-            'f32
-            'f64
-        str := sw self.str_kind
-        'append-any self
-            self.str_cursor
-            end
-            str
-
-    inline begin-list (self cursor)
-        'append self.stack
-            typeinit
-                cursor
-                typeinit;
-    inline end-list (self end single-unwrap?)
-        loc item := 'explode ('pop self.stack)
-        item := if (single-unwrap? and ((countof item) == 1))
-            # unwrap-single
-            @ (copy (& (item @ 0)))
-        else
-            item
-        'append-any self loc end item
-
-fn... parse-buffer (filename : rawstring, cursor : Location,
-    ptr : rawstring, size : usize)
-    ->>
-        range (size + 1)
-        map
-            inline (i)
-                if (i == size)
-                    0:char
-                else
-                    deref (ptr @ i)
-        tokenize
-        map
-            inline (token begin end)
-                pass token begin end
-                    & (ptr @ begin.offset)
-                    & (ptr @ end.offset)
-        stateful
-            inline ()
-                STILParser filename cursor
-
-fn... parse-file (filename : rawstring)
-    f := try! MappedFile.open filename
-    parse-buffer filename (Location) ('data f)
-
-@if main-module?
-#do
-    # 74748 bytes
-    using import compiler.arcmem compiler.File C.stdio
-    arcmem-check true
-    print "--- parsing"
-    s := parse-file module-path
-    print "done."
-    s := & (new := s)
-    #print2
-        /depth 256 (@ (view s))
-    T := typeof s
-    arcmem-check true
-    #print2
-        /depth 256 s
-    filename := .. module-dir "/dump.arc"
-    do
-        f := try! File.open (view filename) "wb"
-        try! arcwrite s
-            &fwrite as ArcWriter
-            f._handle
-        drop f
-    print "--- dropping parsed data"
-    drop s
-    arcmem-check true
-    do
-        f := try! File.open (view filename) "rb"
-        s := try! arcread
-            &fread as ArcReader
-            f._handle
-        s := @ (bitcast s T)
-        for line in s
-            print2
-                /depth 256 line
-        drop f
-    arcmem-check true
-    ;
-
-@endif
-
-do
-    let STILParser parse-buffer parse-file
-    locals;
  No newline at end of file