Verified Commit cbfbaa7d authored by Camil Staps's avatar Camil Staps 🚀

Remove simple usages of Platform

parent 9d4defea
Pipeline #17065 passed with stages
in 18 minutes and 38 seconds
......@@ -3,7 +3,6 @@ implementation module Compiler
import StdFile
import StdList
import Data.Either
import Data.Maybe
import System.OS
......@@ -48,7 +47,7 @@ testThroughFile graph fp w
# (_,w) = fclose f w
# (ok,f,w) = fopen fp FReadData w
# (Right graph_s,f) = graphFromFile f
# (Just graph_s,f) = graphFromFile f
# (_,w) = fclose f w
= deserialize defaultDeserializationSettings graph_s (IF_WINDOWS "Compiler.exe" "compiler") w
CLM:=clm
CLMFLAGS:=\
-I ../../src\
-IL ArgEnv\
-IL Platform\
-IL GraphCopy\
-nt\
......
definition module ABC.Interpreter
from Data.Either import :: Either
from StdMaybe import :: Maybe
from System.FilePath import :: FilePath
:: DeserializationSettings =
......@@ -22,4 +22,4 @@ deserialize :: !DeserializationSettings !SerializedGraph !FilePath !*World -> *(
get_start_rule_as_expression :: !DeserializationSettings !FilePath !*World -> *(a, *World)
graphToFile :: !*SerializedGraph !*File -> *(!*SerializedGraph, !*File)
graphFromFile :: !*File -> *(!Either String *SerializedGraph, !*File)
graphFromFile :: !*File -> *(!Maybe *SerializedGraph, !*File)
......@@ -5,17 +5,14 @@ import StdClass
import StdFile
import StdInt
import StdList
import StdMaybe
import StdMisc
import StdOrdList
import Data._Array
import Data.Either
import ArgEnv
import Data.Error
from Data.Func import `on`, on
import Data.Maybe
import System.CommandLine
import System.File
import System.FilePath
import System._Pointer
import graph_copy_with_names
......@@ -104,7 +101,7 @@ deserialize dsets {graph,descinfo,modules,bytecode} thisexe w
asp bsp csp heap
# graph_node = string_to_interpreter int_syms graph ie_settings
#! (ie,_) = make_finalizer ie_settings
# ie = {ie_finalizer=ie, ie_snode_ptr=0, ie_snodes=unsafeCreateArray 1}
# ie = {ie_finalizer=ie, ie_snode_ptr=0, ie_snodes=create_array_ 1}
= (interpret ie (Finalizer 0 0 graph_node), w)
where
getInterpreterSymbols :: !Pointer -> [Symbol]
......@@ -161,7 +158,7 @@ where
get_start_rule_as_expression :: !DeserializationSettings !FilePath !*World -> *(a, *World)
get_start_rule_as_expression dsets filename w
# ([prog:_],w) = getCommandLine w
# {[0]=prog} = getCommandLine
# (syms,w) = accFiles (read_symbols prog) w
# (bc,w) = readFile filename w
| isError bc = abort "Failed to read the file\n"
......@@ -180,7 +177,7 @@ get_start_rule_as_expression dsets filename w
asp bsp csp heap
# start_node = build_start_node ie_settings
#! (ie,_) = make_finalizer ie_settings
# ie = {ie_finalizer=ie, ie_snode_ptr=0, ie_snodes=unsafeCreateArray 1}
# ie = {ie_finalizer=ie, ie_snode_ptr=0, ie_snodes=create_array_ 1}
= (interpret ie (Finalizer 0 0 start_node), w)
// Obviously, this is not a "valid" finalizer in the sense that it can be
// called from the garbage collector. But that's okay, because we don't add
......@@ -242,24 +239,24 @@ where
writeArray write xs -1 f = f
writeArray write xs i f = writeArray write xs (i-1) (write xs.[i] f)
graphFromFile :: !*File -> *(!Either String *SerializedGraph, !*File)
graphFromFile :: !*File -> *(!Maybe *SerializedGraph, !*File)
graphFromFile f
# (graph,f) = readString f
# (_,descinfo_size,f) = freadi f
# (descinfo,f) = readArray readDescInfo (descinfo_size-1) (unsafeCreateArray descinfo_size) f
# (descinfo,f) = readArray readDescInfo (descinfo_size-1) (create_array_ descinfo_size) f
# (_,modules_size,f) = freadi f
# (modules,f) = readArray readString (modules_size-1) (unsafeCreateArray modules_size) f
# (modules,f) = readArray readString (modules_size-1) (create_array_ modules_size) f
# (bytecode,f) = readString f
# (end,f) = fend f
| not end = (Left "EOF not found after end of graph",f)
| not end = (Nothing,f)
# (err,f) = ferror f
| err = (Left "I/O error while reading graph",f)
| err = (Nothing,f)
= (Right {graph=graph,descinfo=descinfo,modules=modules,bytecode=bytecode},f)
= (Just {graph=graph,descinfo=descinfo,modules=modules,bytecode=bytecode},f)
where
readArray :: !(*File -> *(a, *File)) !Int !*(arr a) !*File -> *(!*arr a, !*File) | Array arr a
readArray _ -1 xs f = (xs,f)
......
......@@ -4,16 +4,15 @@ import StdArray
import StdClass
import StdInt
import Data._Array
import ABC.Interpreter
import ABC.Interpreter.Util
add_shared_node :: !Int !*{a} a -> *(!Int, !*{a}, !Int)
add_shared_node ptr nodes node
# (arraysize,nodes) = usize nodes
# (spot,nodes) = find_empty_spot ptr nodes
| spot == -1
= (arraysize, {copy (arraysize-1) nodes (unsafeCreateArray (arraysize+100)) & [arraysize]=node}, arraysize+1)
= (arraysize, {copy (arraysize-1) nodes (create_array_ (arraysize+100)) & [arraysize]=node}, arraysize+1)
| otherwise
= (spot, {nodes & [spot]=node}, if (spot+1 >= arraysize) 0 (spot+1))
where
......
definition module ABC.Interpreter.Util
from _SystemArray import class Array
from StdMaybe import :: Maybe
from System._Pointer import :: Pointer
from symbols_in_program import :: Symbol
:: Program :== Pointer
parse :: !{#Symbol} !String -> Maybe Program
new_parser :: !{#Symbol} -> Pointer
new_string_char_provider :: !String -> Pointer
free_char_provider_to_false :: !Pointer -> Bool
parse_program :: !Pointer !Pointer -> Int
free_to_false :: !Pointer -> Bool
parse :: !{#Symbol} !String -> Maybe Int
new_parser :: !{#Symbol} -> Int
new_string_char_provider :: !String -> Int
free_char_provider_to_false :: !Int -> Bool
parse_program :: !Int !Int -> Int
free_to_false :: !Int -> Bool
create_array_ :: .Int -> u:(a v:b) | Array a b, [u<=v]
......@@ -5,10 +5,7 @@ import StdBool
import StdClass
import StdInt
import StdList
import Data._Array
import Data.Maybe
import System._Pointer
import StdMaybe
import symbols_in_program
......@@ -33,31 +30,36 @@ import code from library "ucrtbase_library"
OFFSET_PARSER_PROGRAM :== IF_INT_64_OR_32 8 4 // Offset to the program field in the parser struct (parse.h)
parse :: !{#Symbol} !String -> Maybe Program
parse :: !{#Symbol} !String -> Maybe Int
parse syms s
#! cp = new_string_char_provider s
#! parser = new_parser syms
#! res = parse_program parser cp
| free_char_provider_to_false cp || free_to_false cp = Nothing
| res <> 0 = Nothing
#! pgm = readInt parser OFFSET_PARSER_PROGRAM
#! pgm = readInt (parser+OFFSET_PARSER_PROGRAM)
#! parser = free_parser parser parser
| free_to_false parser = Nothing
= Just pgm
where
free_parser :: !Pointer !Pointer -> Pointer
free_parser :: !Int !Int -> Int
free_parser _ _ = code {
ccall free_parser "p:V:p"
}
new_parser :: !{#Symbol} -> Pointer
readInt :: !Int -> Int
readInt _ = code {
load_i 0
}
new_parser :: !{#Symbol} -> Int
new_parser syms
# parser = malloc 100 // size of the parser struct + some extra to be sure
= init parser symbol_n symbol_string_length symbol_string parser
where
symbol_n = size syms
symbol_string_length = sum [size s.symbol_name \\ s <-: syms]
symbol_string = build_symbol_string 0 0 (unsafeCreateArray (symbol_n * IF_INT_64_OR_32 9 5 + symbol_string_length))
symbol_string = build_symbol_string 0 0 (create_array_ (symbol_n * IF_INT_64_OR_32 9 5 + symbol_string_length))
build_symbol_string :: !Int !Int !*{#Char}-> *{#Char}
build_symbol_string i j s
......@@ -75,22 +77,22 @@ where
| i == orgsize = (desti+1, {dest & [desti]='\0'})
| otherwise = copyString org orgsize (i+1) (desti+1) {dest & [desti]=org.[i]}
init :: !Pointer !Int !Int !.{#Char} !Pointer -> Pointer
init :: !Int !Int !Int !.{#Char} !Int -> Int
init _ _ _ _ _ = code {
ccall init_parser "pIIs:V:p"
}
new_string_char_provider :: !String -> Pointer
new_string_char_provider :: !String -> Int
new_string_char_provider s
# cp = malloc 16
= init cp s (size s) 1 cp
where
init :: !Pointer !String !Int !Int !Pointer -> Pointer
init :: !Int !String !Int !Int !Int -> Int
init _ _ _ _ _ = code {
ccall new_string_char_provider "psII:V:p"
}
free_char_provider_to_false :: !Pointer -> Bool
free_char_provider_to_false :: !Int -> Bool
free_char_provider_to_false cp = code {
push_b 0
pushB FALSE
......@@ -99,22 +101,28 @@ free_char_provider_to_false cp = code {
ccall free_char_provider "p:V:I"
}
parse_program :: !Pointer !Pointer -> Int
parse_program :: !Int !Int -> Int
parse_program parser char_provider = code {
ccall parse_program "pp:I"
}
free_to_false :: !Pointer -> Bool
free_to_false :: !Int -> Bool
free_to_false p
# n = free p
= n == 0 && n <> 0
malloc :: !Int -> Pointer
malloc :: !Int -> Int
malloc _ = code {
ccall malloc "I:p"
}
free :: !Pointer -> Int
free :: !Int -> Int
free _ = code {
ccall free "p:I"
}
create_array_ :: .Int -> u:(a v:b) | Array a b, [u<=v]
create_array_ size = code {
updatepop_a 0 7
jmp_ap 1
}
SHELL:=bash
CLM:=clm
CPM:=cpm
override CLMFLAGS+=-I . -IL Platform -IL GraphCopy -ns
override CLMFLAGS+=-I . -IL ArgEnv -IL Platform -IL GraphCopy -ns
override CFLAGS+=\
-std=c99\
-Wall\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment